diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs index 37982f1..7022886 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModel.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; +using System.Text.Json.Serialization; using System.Threading.Tasks; namespace FurnitureAssemblyContracts.ViewModels @@ -17,9 +18,11 @@ namespace FurnitureAssemblyContracts.ViewModels public string Address { get; set; } = string.Empty; [DisplayName("Дата открытия")] public DateTime DateOpening { get; set; } - + [JsonIgnore] public Dictionary Furnitures { get; set; } = new(); [DisplayName("Вместимость")] public int MaxCount { get; set; } + + public List? FurnituresCount { get; set; } = new(); } } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs deleted file mode 100644 index 402ff66..0000000 --- a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace FurnitureAssemblyContracts.ViewModels -{ - public class ShopViewModelWeb - { - public int Id { get; set; } - [DisplayName("Название магазина")] - public string ShopName { get; set; } = string.Empty; - [DisplayName("Адрес магазина")] - public string Address { get; set; } = string.Empty; - [DisplayName("Дата открытия")] - public DateTime DateOpening { get; set; } - public List? Furnitures { get; set; } = new(); - public int MaxCount { get; set; } - } -} diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs index 766dbe5..0a1aa0e 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs @@ -36,7 +36,7 @@ namespace FurnitureAssemblyRestApi.Controllers } [HttpGet] - public ShopViewModelWeb? GetShop(int shopId) + public ShopViewModel? GetShop(int shopId) { try { @@ -49,16 +49,10 @@ namespace FurnitureAssemblyRestApi.Controllers }); if (shop == null) return null; - var shopWeb = new ShopViewModelWeb - { - Id = shop.Id, - ShopName = shop.ShopName, - Address = shop.Address, - DateOpening = shop.DateOpening, - Furnitures = shop.Furnitures.Select(x => x.Value).Select(x => new FurnitureCountViewModel { furniture = x.Item1.FurnitureName, Count = x.Item2 }).ToList(), - MaxCount = shop.MaxCount - }; - return shopWeb; + + shop.FurnituresCount = shop.Furnitures.Select(x => x.Value) + .Select(x => new FurnitureCountViewModel { furniture = x.Item1.FurnitureName, Count = x.Item2 }).ToList(); + return shop; } catch (Exception ex) { diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs index 6bb0bb8..ed25457 100644 --- a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs @@ -139,9 +139,9 @@ namespace FurnitureAssemblyShopWorkApp.Controllers Response.Redirect("Index"); } [HttpGet] - public ShopViewModelWeb? GetShop(int shopId) + public ShopViewModel? GetShop(int shopId) { - return APIClient.GetRequest($"api/shop/getshop?shopId={shopId}"); + return APIClient.GetRequest($"api/shop/getshop?shopId={shopId}"); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml index d17d7ea..969c821 100644 --- a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml @@ -56,8 +56,8 @@ $("#shopName").val(result.shopName); $("#dateOpening").val(new Date(result.dateOpening).toISOString().substring(0, 16)); $("#address").val(result.address); - $("#count").val(result.maxCount); - fillTable(result.furnitures); + $("#count").val(result.maxCount); + fillTable(result.furnituresCount); } }); }