From b84b593b88929ac1d75039b7b895a4a885f3e501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Tue, 16 May 2023 23:01:02 +0400 Subject: [PATCH] fix --- .../Implements/Worker/BuildStorage.cs | 6 +- .../Controllers/BuildController.cs | 33 ++++- .../Controllers/HomeController.cs | 56 +++++++- .../Views/Home/Builds.cshtml | 4 +- .../Views/Home/LinkPurchase.cshtml | 127 +++++++++++++++++- 5 files changed, 212 insertions(+), 14 deletions(-) diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs index 522a159..c1f9e7f 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/BuildStorage.cs @@ -53,13 +53,15 @@ namespace HardwareShopDatabaseImplement.Implements.Worker return null; } using var context = new HardwareShopDatabase(); - return context.Builds + var dadada = context.Builds .Include(x => x.Purchases) .ThenInclude(x => x.Purchase) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BuildName) && x.BuildName == model.BuildName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; - } + return dadada; + + } public BuildViewModel? Insert(BuildBindingModel model) { diff --git a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs index e2dd255..510cd82 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs @@ -3,7 +3,9 @@ using HardwareShopContracts.BindingModels; using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; +using HardwareShopDatabaseImplement.Models.Storekeeper; using HardwareShopDatabaseImplement.Models.Worker; +using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; using Microsoft.AspNetCore.Mvc; using System.ComponentModel; @@ -55,7 +57,33 @@ namespace HardwareShopRestApi.Controllers } } - [HttpPost] + [HttpGet] + public List>? GetBuildPurchase(int buildId) + { + try + { + var result = _buildLogic.ReadElement(new() { Id = buildId }); + List> listPurchase = new List>(); + foreach (var item in result.BuildPurchases) + { + listPurchase.Add(Tuple.Create(new PurchaseViewModel + { + Id = item.Value.Item1.Id, + Sum = item.Value.Item1.Sum, + PurchaseStatus = item.Value.Item1.PurchaseStatus, + }, item.Value.Item2)); + } + return listPurchase; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сборки"); + throw; + } + } + + [HttpPost] public void Create(BuildBindingModel model) { try @@ -69,7 +97,8 @@ namespace HardwareShopRestApi.Controllers } } - [HttpPost] + + [HttpPost] public void Update(BuildBindingModel model) { try diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index a128f3f..48afca1 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -2,10 +2,15 @@ using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; using HardwareShopDatabaseImplement.Models; +using HardwareShopDatabaseImplement.Models.ManyToMany; +using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDatabaseImplement.Models.Worker; using HardwareShopDataModels.Enums; +using HardwareShopDataModels.Models; using HardwareShopWorkerApp.Models; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; +using System.IO.Pipelines; using static System.Net.Mime.MediaTypeNames; namespace HardwareShopWorkerApp.Controllers @@ -143,7 +148,39 @@ namespace HardwareShopWorkerApp.Controllers Response.Redirect("Builds"); } - + [HttpPost] + public void LinkBuildPurchase(int buildId, int purchaseId, int count) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (buildId <= 0) + { + throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + } + if (purchaseId <= 0) + { + throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0"); + } + if (count <= 0) + { + throw new Exception($"Количество сборок в покупке не может быть ниже или равен 0"); + } + var build = APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); + var purchase = APIClient.GetRequest($"api/purchase/getpurchase?purchaseId={purchaseId}"); + build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count)); + APIClient.PostRequest("api/build/update", new BuildBindingModel + { + Id = buildId, + Price = build.Price, + BuildName = build.BuildName, + BuildPurchases = build.BuildPurchases + }); + Response.Redirect("Builds"); + } + + [HttpPost] public void DeleteBuild(int deleteBuildId) { @@ -369,9 +406,18 @@ namespace HardwareShopWorkerApp.Controllers } [HttpGet] - public IActionResult LinkPurchase() + public IActionResult LinkPurchase(int buildId) { - return View(); - } - } + if (APIClient.User == null) + { + return Redirect("~/Home/Enter"); + } + if (buildId <= 0) + { + throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + } + ViewBag.Purchase = APIClient.GetRequest>($"api/purchase/getpurchases?userId={APIClient.User.Id}"); + return View(APIClient.GetRequest>>($"api/build/GetBuildPurchase?buildId={buildId}")); + } + } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml index 2f2d175..631ed28 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/Builds.cshtml @@ -55,9 +55,7 @@ - + diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml index 74db850..82c39f2 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml @@ -1,4 +1,127 @@ - +@using HardwareShopContracts.ViewModels; + +@model List> +@{ + ViewData["Title"] = "Привязка сборок"; + Layout = "~/Views/Shared/_LayoutWorker.cshtml"; +} + +
+

Привязка сборок

+
+ +
+ @{ +

+ +

+ + + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + + } + +
+ Идентификатор покупки + + Цена + + Статус + + Количество сборок в заказе + + Действия +
+ @Html.DisplayFor(modelItem => item.Item1.Id) + + @Html.DisplayFor(modelItem => item.Item1.Sum) + + @Html.DisplayFor(modelItem => item.Item1.PurchaseStatus) + + @Html.DisplayFor(modelItem => item.Item2) + +
+ + +
+
+ } +
+ + + +@section Scripts +{ + +} +@* @{ ViewData["Title"] = "LinkPurchase"; @@ -78,4 +201,4 @@ - \ No newline at end of file +*@ \ No newline at end of file