diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureCountViewModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureCountViewModel.cs new file mode 100644 index 0000000..df713d2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/FurnitureCountViewModel.cs @@ -0,0 +1,15 @@ +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemblyContracts.ViewModels +{ + public class FurnitureCountViewModel + { + public string furniture { get; set; } + public int Count { get; set; } + } +} diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs new file mode 100644 index 0000000..402ff66 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyContracts/ViewModels/ShopViewModelWeb.cs @@ -0,0 +1,22 @@ +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/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs index be8c7b9..275e826 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ShopStorage.cs @@ -160,8 +160,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return null; } shop.Update(model); - context.SaveChanges(); - shop.UpdateFurnitures(context, model); + context.SaveChanges(); transaction.Commit(); return shop.GetViewModel; } diff --git a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs index 9b7db61..766dbe5 100644 --- a/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs +++ b/FurnitureAssembly/FurnitureAssemblyRestApi/Controllers/ShopController.cs @@ -1,8 +1,8 @@ -using FurnitureAssemblyContracts.BindingModels; +using DocumentFormat.OpenXml.Bibliography; +using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using FurnitureAssemblyContracts.SearchModels; using FurnitureAssemblyContracts.ViewModels; -using FurnitureAssemblyDatabaseImplement.Models; using Microsoft.AspNetCore.Mvc; namespace FurnitureAssemblyRestApi.Controllers @@ -36,14 +36,29 @@ namespace FurnitureAssemblyRestApi.Controllers } [HttpGet] - public ShopViewModel? GetShop(int shopId) + public ShopViewModelWeb? GetShop(int shopId) { try { - return _shop.ReadElement(new ShopSearchModel + // получаем обычную ShopViewModel из бизнес-логики, а затем преобразуем в новую модель для передачи в "стороннее" приложение - на клиент + // главное отличие от предыдущей модели в способе передачи изделий - теперь они представлены в виде списка сериализуемых моделей FurnitureCountViewModel + // данное решение необходимо для корректной сериализации изделий и их количества в магазине + var shop = _shop.ReadElement(new ShopSearchModel { Id = shopId }); + 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; } catch (Exception ex) { diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs index 5d52b9a..6bb0bb8 100644 --- a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Controllers/HomeController.cs @@ -121,11 +121,28 @@ namespace FurnitureAssemblyShopWorkApp.Controllers Response.Redirect("Index"); } [HttpGet] - public ShopViewModel GetShop() + public IActionResult Replenishment() { - + ViewBag.Shops = APIClient.GetRequest>("api/shop/getshoplist"); + ViewBag.Furnitures = APIClient.GetRequest>("api/main/getfurniturelist"); + return View(); } + [HttpPost] + public void Replenishment(int shop, int furniture, int count) + { + if (!APIClient.isAuth) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest($"api/shop/addfurniturestoshop", ( new ShopBindingModel { Id = shop }, new FurnitureBindingModel {Id =furniture}, count)); + Response.Redirect("Index"); + } + [HttpGet] + public ShopViewModelWeb? GetShop(int shopId) + { + return APIClient.GetRequest($"api/shop/getshop?shopId={shopId}"); + } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Index.cshtml b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Index.cshtml index 508b2da..183f696 100644 --- a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Index.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Index.cshtml @@ -16,6 +16,8 @@

Создать магазин Удалить магазин + Редактировать магазин + Пополнить магазин

diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Replenishment.cshtml b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Replenishment.cshtml new file mode 100644 index 0000000..3255701 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Replenishment.cshtml @@ -0,0 +1,27 @@ +@{ + ViewData["Title"] = "Replenishment"; +} +
+

Пополнение магазина

+
+ +
+
Название магазина:
+
+ +
+
+
Изделие:
+
+ +
+
+
+
Количество:
+
+
+
+
+ \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml new file mode 100644 index 0000000..d17d7ea --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyShopWorkApp/Views/Home/Update.cshtml @@ -0,0 +1,72 @@ +@{ + ViewData["Title"] = "Update"; +} +
+

Редактирование магазина

+
+ +
+
Магазин:
+
+ +
+
+
+
Название:
+
+
+
+
Дата открытия:
+
+
+
Адрес:
+
+
+
+
Вместимость:
+
+
+
+
Изделия в магазине:
+
+
+ + + + + + + + + +
ИзделиеКоличество
+ + +
+ + + \ No newline at end of file