|
1 | | -using System; |
2 | 1 | using System.Collections.Generic; |
3 | 2 | using System.Linq; |
4 | 3 | using System.Threading.Tasks; |
| 4 | +using dotnet.Models; |
5 | 5 | using Microsoft.AspNetCore.Mvc; |
| 6 | +using Tarantool.Client; |
| 7 | +using Tarantool.Client.Model; |
| 8 | +using Tarantool.Client.Model.Enums; |
6 | 9 |
|
7 | 10 | namespace dotnet.Controllers |
8 | 11 | { |
9 | 12 | public class HomeController : Controller |
10 | 13 | { |
11 | | - public IActionResult Index() |
| 14 | + private readonly Box _box; |
| 15 | + private readonly Space _space; |
| 16 | + private readonly Index _primaryIndex; |
| 17 | + private readonly Index _secondaryIndex; |
| 18 | + |
| 19 | + public HomeController(Box box) |
| 20 | + { |
| 21 | + this._box = box; |
| 22 | + |
| 23 | + var result = this.Initialize().GetAwaiter().GetResult(); |
| 24 | + this._space = result.Item1; |
| 25 | + this._primaryIndex = result.Item2; |
| 26 | + this._secondaryIndex = result.Item3; |
| 27 | + } |
| 28 | + |
| 29 | + private async Task<Tarantool.Client.Model.Tuple<Space, Index, Index>> Initialize() |
12 | 30 | { |
13 | | - return View(); |
| 31 | + var schema = this._box.GetSchema(); |
| 32 | + |
| 33 | + var space = await schema.GetSpace("some_space"); |
| 34 | + var primaryIndex = await space.GetIndex("primary"); |
| 35 | + var index = await space.GetIndex("some_secondary_index"); |
| 36 | + |
| 37 | + return Tarantool.Client.Model.Tuple.Create(space, primaryIndex, index); |
| 38 | + } |
| 39 | + |
| 40 | + public async Task<ViewResult> Index() |
| 41 | + { |
| 42 | + var primaryData = await this._primaryIndex.Select<Tuple<long>, Tuple<long, string, long>>(Tuple.Create(-1L), new SelectOptions { Iterator = Iterator.All }); |
| 43 | + var secondaryData = await this._secondaryIndex.Select<Tuple<long>, Tuple<long, string, long>>(Tuple.Create(5L), new SelectOptions { Iterator = Iterator.Ge }); |
| 44 | + |
| 45 | + return View(new TestData |
| 46 | + { |
| 47 | + AllDogs = primaryData.Data.Select(x => new Dog(x)).ToArray(), |
| 48 | + DogsOlder5Years = secondaryData.Data.Select(x => new Dog(x)).ToArray() |
| 49 | + }); |
14 | 50 | } |
15 | 51 | } |
16 | 52 | } |
0 commit comments