From 897acf6c087388744030ef2560f2381f547f00c6 Mon Sep 17 00:00:00 2001 From: "DozorovaA.A" Date: Fri, 19 May 2023 11:04:05 +0400 Subject: [PATCH] add Furniture --- .../Implements/FurnitureStorage.cs | 2 +- .../Controllers/HomeController.cs | 128 +++++++++++++++++- .../Views/Home/CreateFurniture.cshtml | 95 +++++++++++++ .../Views/Home/DeleteFurniture.cshtml | 27 ++++ .../Views/Home/GetFurnitureList.cshtml | 81 ++++++++++- .../Views/Home/UpdateFurniture.cshtml | 93 +++++++++++++ .../Views/Home/UpdateMaterial.cshtml | 9 +- .../Views/Shared/_Layout.cshtml | 2 +- 8 files changed, 426 insertions(+), 11 deletions(-) create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateFurniture.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteFurniture.cshtml create mode 100644 FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateFurniture.cshtml diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs index 52dfd41..3c8769d 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/FurnitureStorage.cs @@ -20,7 +20,6 @@ namespace FurnitureAssemblyDatabaseImplement.Implements return context.Furnitures .Include(x => x.User) .Include(x => x.Materials) - .ThenInclude(x => x.Material).ToList() .Select(x => x.GetViewModel).ToList(); } public List GetFilteredList(FurnitureSearchModel model) @@ -81,6 +80,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements { var furniture = context.Furnitures .Include(x => x.User) + .Include(x => x.Materials) .FirstOrDefault(rec => rec.Id == model.Id); if (furniture == null) { diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs index 6ccc947..1153eae 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Controllers/HomeController.cs @@ -1,5 +1,6 @@ using FurnitureAssemblyContracts.BindingModels; using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; using FurnitureAssemblyStoreKeeperClientApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -96,7 +97,8 @@ namespace FurnitureAssemblyStoreKeeperClientApp.Controllers Response.Redirect("Enter"); return; } - [HttpGet] + #region Scope + [HttpGet] public IActionResult GetScopeList() { return View(APIClient.GetRequest>($"api/scope/GetScopeList")); @@ -177,7 +179,8 @@ namespace FurnitureAssemblyStoreKeeperClientApp.Controllers }); Response.Redirect("GetScopeList"); } - +#endregion + #region Material [HttpGet] public IActionResult GetMaterialsList() { @@ -269,6 +272,127 @@ namespace FurnitureAssemblyStoreKeeperClientApp.Controllers }); Response.Redirect("GetMaterialsList"); } + #endregion + #region Furniture + [HttpGet] + public IActionResult GetFurnitureList() + { + + return View(APIClient.GetRequest>($"api/furniture/getfurniturelist")); + } + + [HttpGet] + public IActionResult CreateFurniture() + { + return View(); + } + [HttpPost] + public double Calc(int count, int furniture) + { + var prod = APIClient.GetRequest($"api/main/getfurniture?furnitureId={furniture}" + ); + return count * (prod?.Cost ?? 1); + } + [HttpPost] + public void CreateFurniture(string name, int userId, int[] MaterialsIds, int[] counts) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + if(counts == null || MaterialsIds.Length != counts.Length) + { + throw new Exception("Неверно заполнены компоненты"); + } + var materials = APIClient.GetRequest>($"api/material/getmateriallist"); + Dictionary FurnitureMaterials = new Dictionary(); + double cost = 0; + for(int i = 0; i m.Id == MaterialsIds[i]).FirstOrDefault(), counts[i]); + FurnitureMaterials.Add(MaterialsIds[i], elem); + cost += counts[i] * materials.Where(m => m.Id == MaterialsIds[i]).FirstOrDefault().Cost; + + } + + APIClient.PostRequest("api/furniture/addfurniture", new FurnitureBindingModel + { + Name = name, + Cost = cost, + UserId = userId, + DateCreate = DateTime.UtcNow, + FurnitureMaterials = FurnitureMaterials + }); + Response.Redirect("GetMaterialsList"); + } + + [HttpGet] + public IActionResult UpdateFurniture(int id) + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + var model = APIClient.GetRequest($"api/furniture/GetFurniture?id={id}"); + return View(model); + } + [HttpPost] + public void UpdateFurniture(int id, string name, double cost, int userId, int[] MaterialsIds, int[] counts) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали?"); + } + if (string.IsNullOrEmpty(name)) + { + throw new Exception("Название не указано"); + } + var materials = APIClient.GetRequest>($"api/material/getmateriallist"); + Dictionary FurnitureMaterials = new Dictionary(); + double price = 0; + for (int i = 0; i < counts.Length; i++) + { + var elem = (materials.Where(m => m.Id == MaterialsIds[i]).FirstOrDefault(), counts[i]); + FurnitureMaterials.Add(MaterialsIds[i], elem); + price += elem.Item1.Cost * elem.Item2; + } + APIClient.PostRequest("api/furniture/updatefurniture", new FurnitureBindingModel + { + Id = id, + Name = name, + Cost = price, + UserId=userId, + FurnitureMaterials = FurnitureMaterials + }); + Response.Redirect("GetFurnitureList"); + } + [HttpGet] + public IActionResult DeleteFurniture() + { + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/furniture/GetFurnitureList")); + } + [HttpPost] + public void DeleteFurniture(int furniture) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали"); + } + APIClient.PostRequest("api/furniture/deletefurniture", new MaterialBindingModel + { + Id = furniture, + }); + Response.Redirect("GetFurnitureList"); + } + #endregion } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateFurniture.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateFurniture.cshtml new file mode 100644 index 0000000..360ed5c --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/CreateFurniture.cshtml @@ -0,0 +1,95 @@ +@using FurnitureAssemblyContracts.ViewModels +@{ + ViewData["Title"] = "Создание мебели"; + var materialList = APIClient.GetRequest>($"api/material/GetMaterialList"); + var userList = APIClient.GetRequest>($"api/user/GetUserList"); +} +
+

Создание мебели

+
+
+
+
Название:
+
+
+
+
Стоимость:
+
+
+
Изготовитель:
+ +
+ +
+
+ + + + + + + + + + + @foreach (var item in materialList) + { + + + + + + + } + +
+ + + Название + + Стоимость + + Количество +
+ + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + +
+ +
+
+
+
+ + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteFurniture.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteFurniture.cshtml new file mode 100644 index 0000000..b6f983e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/DeleteFurniture.cshtml @@ -0,0 +1,27 @@ +@using FurnitureAssemblyContracts.ViewModels; +@{ + ViewData["Title"] = "Удаление мебели"; +} +@model List +
+

Удаление мебели

+
+
+
+
Выбранная мебель:
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml index e1dd794..3d8e446 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/GetFurnitureList.cshtml @@ -1,5 +1,80 @@ -@* - For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 -*@ +@using FurnitureAssemblyContracts.ViewModels + +@model List + @{ + ViewData["Title"] = "Мебель"; } + +
+

Мебель

+
+ +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } + + + + + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + + } + +
+ Id + + Название + + Стоимость + + Дата создания + + Изготовитель + + +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + @Html.DisplayFor(modelItem => item.DateCreate) + + @Html.DisplayFor(modelItem => item.UserName) + + +
+ + } +
\ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateFurniture.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateFurniture.cshtml new file mode 100644 index 0000000..63b1add --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateFurniture.cshtml @@ -0,0 +1,93 @@ +@using FurnitureAssemblyContracts.ViewModels +@model FurnitureViewModel +@{ + ViewData["Title"] = "Обновление мебели"; + var materialList = APIClient.GetRequest>($"api/material/GetMaterialList"); + var userList = APIClient.GetRequest>($"api/user/GetUserList"); +} +
+

Обновление мебели

+
+
+
+
Название:
+
+
+
+
Стоимость:
+
@Html.DisplayFor(modelItem => Model.Cost)
+
+
+
Изготовитель:
+
+
+ +
+
+ + + + + + + + + + + + + @foreach (var item in materialList) + { + + + + + + + + } + +
+ + Название + + Стоимость + + Количество + + Изготовитель +
+ @if(Model.FurnitureMaterials.Keys.Contains(item.Id)) + { + + + } + else + { + + + } + + + @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Cost) + + + + @Html.DisplayFor(modelItem => item.UserName) +
+ +
+
+
+
+ + diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml index 7641f6f..fb4baca 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Home/UpdateMaterial.cshtml @@ -32,10 +32,7 @@
Стоимость:
-
-
-
-
+
Область применения:
@@ -62,5 +59,9 @@
+
+
+
+
diff --git a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml index 12c4571..7d3fd94 100644 --- a/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml +++ b/FurnitureAssembly/FurnitureAssemblyStoreKeeperClientApp/Views/Shared/_Layout.cshtml @@ -31,7 +31,7 @@ else {