From ae16a70b322f0275b56eb8cf5a287782503941ef Mon Sep 17 00:00:00 2001 From: DavidMakarov Date: Fri, 17 May 2024 01:17:21 +0400 Subject: [PATCH] fix in controllers --- .../Controllers/ShopController.cs | 59 +++++-------------- .../Controllers/HomeController.cs | 29 +-------- .../FlowerShopShopApp/Views/Home/Shop.cshtml | 4 +- .../Views/Home/Supply.cshtml | 4 +- .../Views/Shared/_Layout.cshtml | 12 ++-- 5 files changed, 26 insertions(+), 82 deletions(-) diff --git a/FlowerShop/FlowerShopRestApi/Controllers/ShopController.cs b/FlowerShop/FlowerShopRestApi/Controllers/ShopController.cs index def4765..0f30c9a 100644 --- a/FlowerShop/FlowerShopRestApi/Controllers/ShopController.cs +++ b/FlowerShop/FlowerShopRestApi/Controllers/ShopController.cs @@ -32,51 +32,20 @@ namespace FlowerShopRestApi.Controllers throw; } } - [HttpGet] - public Tuple, List>? GetShopFlowers(int shopId) - { - try - { - var shop = _logic.ReadElement(new() { Id = shopId }); - if (shop == null) - { - return null; - } - var tuple = Tuple.Create(shop, - shop.ShopFlowers.Select(x => new FlowerViewModel() - { - Id = x.Value.Item1.Id, - Price = x.Value.Item1.Price, - FlowerName = x.Value.Item1.FlowerName, - }).ToList(), - shop.ShopFlowers.Select(x => x.Value.Item2).ToList()); - return tuple; - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения магазина с цветами"); - throw; - } - } - [HttpGet] - public Dictionary? GetListFlower(int shopId) - { - try - { - var shop = _logic.ReadElement(new() { Id = shopId }); - if (shop == null) - { - return null; - } - return shop.ShopFlowers; - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения цветов магазина"); - throw; - } - } - [HttpPost] + [HttpGet] + public ShopViewModel? GetShop(int shopId) + { + try + { + return _logic.ReadElement(new ShopSearchModel { Id = shopId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка магазинов"); + throw; + } + } + [HttpPost] public void CreateShop(ShopBindingModel model) { try diff --git a/FlowerShop/FlowerShopShopApp/Controllers/HomeController.cs b/FlowerShop/FlowerShopShopApp/Controllers/HomeController.cs index 47cccd0..d36429f 100644 --- a/FlowerShop/FlowerShopShopApp/Controllers/HomeController.cs +++ b/FlowerShop/FlowerShopShopApp/Controllers/HomeController.cs @@ -92,36 +92,13 @@ namespace FlowerShopShopApp.Controllers } [HttpGet] - public Tuple? GetShopFlowers(int shopId) - { - var result = APIClient.GetRequest, List>> - ($"api/shop/getshopflowers?shopId={shopId}"); - if (result == null) - { - return default; - } - string flowerTable = ""; - for (int i = 0; i < result.Item2.Count; i++) - { - var flower = result.Item2[i]; - var count = result.Item3[i]; - flowerTable += ""; - flowerTable += $"{flower.FlowerName}"; - flowerTable += $"{flower.Price}"; - flowerTable += $"{count}"; - flowerTable += ""; - } - return Tuple.Create(result.Item1, flowerTable); - } - [HttpGet] - public IActionResult Update() + public IActionResult Update(int Id) { if (!APIClient.AuthenticationDone) { return Redirect("~/Home/Enter"); } - ViewBag.Shops = APIClient.GetRequest>($"api/shop/getshoplist"); - return View("Shop"); + return View("Shop", APIClient.GetRequest($"api/shop/getshop?shopId={Id}")); } [HttpPost] @@ -187,7 +164,7 @@ namespace FlowerShopShopApp.Controllers { throw new Exception("Количество должно быть больше 0"); } - APIClient.PostRequest("api/shop/storereplenishment", Tuple.Create( + APIClient.PostRequest("api/shop/makesupply", Tuple.Create( new ShopSearchModel() { Id = shop }, new FlowerViewModel() { Id = flower }, count diff --git a/FlowerShop/FlowerShopShopApp/Views/Home/Shop.cshtml b/FlowerShop/FlowerShopShopApp/Views/Home/Shop.cshtml index 3110dbe..01644fb 100644 --- a/FlowerShop/FlowerShopShopApp/Views/Home/Shop.cshtml +++ b/FlowerShop/FlowerShopShopApp/Views/Home/Shop.cshtml @@ -64,8 +64,8 @@ @foreach (var item in Model.ShopFlowers) { - @Html.DisplayFor(modelItem => item.Value.Item1.FlowerName) - @Html.DisplayFor(modelItem => item.Value.Item2) + @Html.DisplayFor(ShopItem => item.Value.Item1.FlowerName) + @Html.DisplayFor(ShopItem => item.Value.Item2) } diff --git a/FlowerShop/FlowerShopShopApp/Views/Home/Supply.cshtml b/FlowerShop/FlowerShopShopApp/Views/Home/Supply.cshtml index 29b8bcf..f8fa016 100644 --- a/FlowerShop/FlowerShopShopApp/Views/Home/Supply.cshtml +++ b/FlowerShop/FlowerShopShopApp/Views/Home/Supply.cshtml @@ -10,8 +10,8 @@
- - + +
diff --git a/FlowerShop/FlowerShopShopApp/Views/Shared/_Layout.cshtml b/FlowerShop/FlowerShopShopApp/Views/Shared/_Layout.cshtml index f91eda6..489940c 100644 --- a/FlowerShop/FlowerShopShopApp/Views/Shared/_Layout.cshtml +++ b/FlowerShop/FlowerShopShopApp/Views/Shared/_Layout.cshtml @@ -11,8 +11,8 @@