From 7103e43d37569ed31d63bc541be005da4c05e93e Mon Sep 17 00:00:00 2001 From: dasha Date: Sat, 8 Apr 2023 14:19:28 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B4=D0=B0=D0=BA=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SushiBarDatabaseImplement/Models/Shop.cs | 1 + .../SushiBarDatabase.cs | 3 ++- .../Controllers/ShopController.cs | 4 ++-- .../Controllers/HomeController.cs | 20 ++++++++++++++++--- .../SushiBarShopApp/Views/Home/Update.cshtml | 4 ++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs index f7ac029..54482fc 100644 --- a/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs +++ b/SushiBar/SushiBarDatabaseImplement/Models/Shop.cs @@ -80,6 +80,7 @@ namespace SushiBarDatabaseImplement.Models { // удалили те, которых нет в модели context.ShopSushi.RemoveRange(shopSushi.Where(rec => !model.ListSushi.ContainsKey(rec.SushiId))); context.SaveChanges(); + shopSushi = context.ShopSushi.Where(rec => rec.ShopId == model.Id).ToList(); // обновили количество у существующих записей foreach (var updateSushi in shopSushi) { diff --git a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs index 237eb71..5d56115 100644 --- a/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs +++ b/SushiBar/SushiBarDatabaseImplement/SushiBarDatabase.cs @@ -9,7 +9,8 @@ namespace SushiBarDatabaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-D8KMQQU\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + // D8KMQQU comp JC256C6 nout + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-JC256C6\SQLEXPRESS;Initial Catalog=SushiBarDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/SushiBar/SushiBarRestApi/Controllers/ShopController.cs b/SushiBar/SushiBarRestApi/Controllers/ShopController.cs index b6321ac..db72cf6 100644 --- a/SushiBar/SushiBarRestApi/Controllers/ShopController.cs +++ b/SushiBar/SushiBarRestApi/Controllers/ShopController.cs @@ -37,14 +37,14 @@ namespace SushiBarRestApi.Controllers } [HttpGet] - public Tuple>? GetShop(int shopId) + public Tuple>>? GetShop(int shopId) { try { var elem = _shop.ReadElement(new ShopSearchModel { Id = shopId }); if (elem == null) return null; - return Tuple.Create(elem, elem.ListSushi); + return Tuple.Create(elem, elem.ListSushi.Select(x => Tuple.Create(x.Value.Item1.SushiName, x.Value.Item2)).ToList()); } catch (Exception ex) { diff --git a/SushiBar/SushiBarShopApp/Controllers/HomeController.cs b/SushiBar/SushiBarShopApp/Controllers/HomeController.cs index ac1fe00..0737069 100644 --- a/SushiBar/SushiBarShopApp/Controllers/HomeController.cs +++ b/SushiBar/SushiBarShopApp/Controllers/HomeController.cs @@ -155,14 +155,28 @@ namespace SushiBarShopApp.Controllers } [HttpGet] - public Tuple>? GetShop(int shopId) + public Tuple? GetShop(int shopId) { if (APIClient.Access == false) { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - var result = APIClient.GetRequest>>($"api/shop/getshop?shopid={shopId}"); - return result; + var result = APIClient.GetRequest>>>($"api/shop/getshop?shopid={shopId}"); + if (result == null) + { + return default; + } + string table = ""; + for (int i = 0; i < result.Item2.Count; i++) + { + var sushi = result.Item2[i].Item1; + var count = result.Item2[i].Item2; + table += ""; + table += $"{sushi}"; + table += $"{count}"; + table += ""; + } + return Tuple.Create(result.Item1, table); } public IActionResult AddSushi() diff --git a/SushiBar/SushiBarShopApp/Views/Home/Update.cshtml b/SushiBar/SushiBarShopApp/Views/Home/Update.cshtml index fddb343..58c39a5 100644 --- a/SushiBar/SushiBarShopApp/Views/Home/Update.cshtml +++ b/SushiBar/SushiBarShopApp/Views/Home/Update.cshtml @@ -49,7 +49,7 @@ - + @@ -69,7 +69,7 @@ $('#address').val(result.item1.address); $('#date').val(result.item1.dateOpening); $('#count').val(result.item1.maxCountSushi); - $('#table').html(result.item2); + $('#table-elements').html(result.item2); } }); };