diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/GoodLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/GoodLogic.cs index 2120a54..94e3942 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/GoodLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Storekeeper/GoodLogic.cs @@ -1,5 +1,5 @@ using HardwareShopContracts.BindingModels; -using HardwareShopContracts.BuisnessLogicsContracts; +using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.ViewModels; diff --git a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/CreateGood.cshtml b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/CreateGood.cshtml index 7ac7938..886cbb7 100644 --- a/HardwareShop/HardwareShopClientApp/Views/Storekeeper/CreateGood.cshtml +++ b/HardwareShop/HardwareShopClientApp/Views/Storekeeper/CreateGood.cshtml @@ -119,6 +119,7 @@ resultTable.innerHTML = '' let price = 0; list.forEach((elem) => { + console.log(elem); resultTable.innerHTML += `${elem.component.componentName}${elem.count}${Math.round(elem.component.cost * elem.count * 100) / 100}` price += elem.component.cost * elem.count }) diff --git a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs index cbabb52..ad97e96 100644 --- a/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs +++ b/HardwareShop/HardwareShopContracts/BindingModels/PurchaseBindingModel.cs @@ -1,4 +1,5 @@ -using HardwareShopDataModels.Enums; +using HardwareShopContracts.ViewModels; +using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; namespace HardwareShopContracts.BindingModels @@ -18,5 +19,17 @@ namespace HardwareShopContracts.BindingModels public Dictionary PurchaseGoods { get; set; } = new(); public Dictionary PurchaseBuilds { get; set; } = new(); - } + + public List ListPurchaseGoods + { + get; + set; + } = new(); + + public List PurchaseGoodsCounts + { + get; + set; + } = new(); + } } diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IGoodLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IGoodLogic.cs index 2103997..1b7d47e 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IGoodLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IGoodLogic.cs @@ -2,7 +2,7 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; -namespace HardwareShopContracts.BuisnessLogicsContracts +namespace HardwareShopContracts.BusinessLogicsContracts { public interface IGoodLogic { diff --git a/HardwareShop/HardwareShopRestApi/Controllers/GoodController.cs b/HardwareShop/HardwareShopRestApi/Controllers/GoodController.cs index 10dfa86..04b1ef9 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/GoodController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/GoodController.cs @@ -1,5 +1,5 @@ using HardwareShopContracts.BindingModels; -using HardwareShopContracts.BuisnessLogicsContracts; +using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.ViewModels; using HardwareShopDataModels.Models; using Microsoft.AspNetCore.Mvc; @@ -20,7 +20,21 @@ namespace HardwareShopRestApi.Controllers _good = good; } - [HttpGet] + [HttpGet] + public List? GetAllGoods() + { + try + { + return _good.ReadList(null); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка всех товаров"); + throw; + } + } + + [HttpGet] public List? GetGoods(int userId) { try diff --git a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs index 4796eeb..cd36916 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs @@ -2,6 +2,8 @@ using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDataModels.Models; using HardwareShopRestApi.Controllers; using Microsoft.AspNetCore.Mvc; using System.Xml.Linq; @@ -16,12 +18,90 @@ namespace HardwareShopRestApi.Controllers private readonly IPurchaseLogic _purchaseLogic; - public PurchaseController(IPurchaseLogic purchaseLogic, ILogger logger) + private readonly IGoodLogic _goodLogic; + + public PurchaseController(IPurchaseLogic purchaseLogic, IGoodLogic goodLogic, ILogger logger) { _logger = logger; _purchaseLogic = purchaseLogic; - } - } + _goodLogic = goodLogic; + } + + [HttpGet] + public List? GetPurchases(int userId) + { + try + { + return _purchaseLogic.ReadList(new() { UserId = userId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка товаров"); + throw; + } + } + + [HttpGet] + public PurchaseViewModel? GetPurchase(int id) + { + try + { + return _purchaseLogic.ReadElement(new() { Id = id }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения товара"); + throw; + } + } + + [HttpPost] + public void CreatePurchase(PurchaseBindingModel model) + { + try + { + for (int i = 0; i < model.PurchaseGoodsCounts.Count; i++) + { + model.PurchaseGoods.Add(model.ListPurchaseGoods[i].Id, + (model.ListPurchaseGoods[i] as IGoodModel, model.PurchaseGoodsCounts[i])); + } + _purchaseLogic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания товара"); + throw; + } + } + + [HttpPost] + public void UpdatePurchase(PurchaseBindingModel model) + { + try + { + _purchaseLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных товара"); + throw; + } + } + + [HttpPost] + public void DeletePurchase(PurchaseBindingModel model) + { + try + { + _purchaseLogic.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления товара"); + throw; + } + } + } } diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index e33e5dc..343bd27 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -270,23 +270,62 @@ namespace HardwareShopWorkerApp.Controllers [HttpGet] public IActionResult Purchases() { - return View(); - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/purchase/getpurchases?userId={APIClient.User.Id}")); + } [HttpPost] public void Purchases(int id) { - Response.Redirect("Purchase"); + Response.Redirect("CreatePurchase"); } + [HttpGet] + public GoodViewModel? GetGood(int Id) + { + if (APIClient.User == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + var result = APIClient.GetRequest($"api/good/getgood?id={Id}"); + if (result == null) + { + return default; + } + return result; + } - [HttpGet] - public IActionResult Purchase() + [HttpGet] + public IActionResult CreatePurchase() { - return View(); - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Goods = APIClient.GetRequest>($"api/good/GetAllGoods"); + return View(); + } - public IActionResult WorkerReport() + [HttpPost] + public void CreatePurchase([FromBody] PurchaseBindingModel purchaseModel) + { + if (APIClient.User == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (purchaseModel.Sum <= 0) + { + throw new Exception("Цена должна быть больше 0"); + } + purchaseModel.UserId = APIClient.User.Id; + APIClient.PostRequest("api/purchase/createpurchase", purchaseModel); + } + + [HttpGet] + public IActionResult WorkerReport() { return View(); } diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml new file mode 100644 index 0000000..a999da5 --- /dev/null +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml @@ -0,0 +1,193 @@ +@using HardwareShopContracts.ViewModels +@{ + ViewData["Title"] = "CreatePurchase"; + Layout = "~/Views/Shared/_LayoutWorker.cshtml"; +} + +
+

Создание покупки

+
+ +
+
+ + +
+

Товары

+
+ + +
+ + + + + + + + + + +
ТоварКоличествоЦена
+
+ +
+
+ + + +@section Scripts + { + +} + + +@*
+
+
+

Товары

+
+
+ + + + + + + + + + + +
+ Номер + + Название товара + + Цена + + Количество +
+
+
+
+ + + + + +
+ +
+*@ \ No newline at end of file diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchase.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchase.cshtml deleted file mode 100644 index bb004f4..0000000 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchase.cshtml +++ /dev/null @@ -1,68 +0,0 @@ -@{ - ViewData["Title"] = "Purchase"; - Layout = "~/Views/Shared/_LayoutWorker.cshtml"; -} - -
-
-
-

Товары

-
-
- - - - - - - - - - - -
- Номер - - Название товара - - Цена - - Количество -
-
-
-
- - - - - -
- -
diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml index b45349f..1813ffa 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml @@ -1,12 +1,27 @@ -@{ +@using HardwareShopContracts.ViewModels +@model List +@{ ViewData["Title"] = "Purchases"; Layout = "~/Views/Shared/_LayoutWorker.cshtml"; } -
+
+ @{ + if (Model == null) + { +

Введите пароль

+ return; + }

Покупки

+

+ Добавить + + + + +

@@ -27,14 +42,38 @@ + @foreach (var item in Model) + { + + + + + + @**@ + + }
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.DatePurchase) + + @Html.DisplayFor(modelItem => item.Sum) + + @Html.DisplayFor(modelItem => item.PurchaseStatus) + +
+ + +
+
- - + + @* - + *@
- + } +