From f032fc0f44e1ffe68ef3f53a5e7ce0af07cc723f 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 18:35:08 +0400 Subject: [PATCH 01/15] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D1=81=D0=BC=D0=B5=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=D1=81=D0=B0=20=D1=83=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BA=D1=83=D0=BF=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PurchaseController.cs | 2 +- .../Controllers/HomeController.cs | 22 +++++++++ .../Views/Home/Purchases.cshtml | 48 +++++-------------- 3 files changed, 35 insertions(+), 37 deletions(-) diff --git a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs index b97f1fe..b459d3e 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs @@ -76,7 +76,7 @@ namespace HardwareShopRestApi.Controllers { try { - _purchaseLogic.Update(model); + _purchaseLogic.DeliveryPurchase(model); } catch (Exception ex) { diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index 343bd27..a128f3f 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -324,6 +324,28 @@ namespace HardwareShopWorkerApp.Controllers APIClient.PostRequest("api/purchase/createpurchase", purchaseModel); } + [HttpPost] + public void UpdatePurchase(int id, int status) + { + if (APIClient.User == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (id <= 0) + { + throw new Exception("Некорректный идентификатор"); + } + if (status <= 0) + { + throw new Exception("Некорректный статус"); + } + APIClient.PostRequest("api/purchase/updatepurchase", new PurchaseBindingModel + { + Id = id, + PurchaseStatus = (PurchaseStatus)status + }); + } + [HttpGet] public IActionResult WorkerReport() { diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml index 245cb59..bcdb47f 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/Purchases.cshtml @@ -18,13 +18,11 @@

Добавить - -

-
- +
+
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"; +} + +
+

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

+
+ +
+ @{ +

+ +

+
@@ -100,10 +98,8 @@ var table = document.getElementById("table"); var remove = document.getElementById("delete"); - var inwork = document.getElementById("inwork"); - var ready = document.getElementById("ready"); var done = document.getElementById("done"); - var order = 0; + var purchase = 0; for (var i = 1; i < table.rows.length; i++) { table.rows[i].onclick = function () { // remove the background from the previous selected row @@ -114,46 +110,26 @@ index = this.rowIndex; // add class selected to the row this.classList.toggle("selected"); - order = parseInt(this.cells[0].innerText); + purchase = parseInt(this.cells[0].innerText); remove.addEventListener("click", () => { - console.log('try to delete order') + console.log('try to delete purchase') $.ajax( { - url: `/Storekeeper/DeleteOrder`, + url: `/Home/DeletePurchase`, type: 'POST', - data: { id: order } + data: { id: purchase } } - ) - }) - inwork.addEventListener("click", () => { - console.log('try to delete order') - $.ajax( - { - url: `/Storekeeper/UpdateOrder`, - type: 'POST', - data: { id: order, status: 1 } - } - ) - }) - ready.addEventListener("click", () => { - console.log('try to delete order') - $.ajax( - { - url: `/Storekeeper/UpdateOrder`, - type: 'POST', - data: { id: order, status: 2 } - } - ) + ).done(() => window.location.href = '/Home/Purchase') }) done.addEventListener("click", () => { - console.log('try to delete order') + console.log('try to delete purchase') $.ajax( { - url: `/Storekeeper/UpdateOrder`, + url: `/Home/UpdatePurchase`, type: 'POST', - data: { id: order, status: 3 } + data: { id: purchase, status: 1 } } - ) + ).done(() => window.location.href = '/Home/Purchases') }) }; } From d498e507ff25d05b9a7b7325ac6e01f94e5a801a 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 19:49:58 +0400 Subject: [PATCH 02/15] fix purchase --- .../BusinessLogics/Worker/PurchaseLogic.cs | 2 +- .../StoragesContracts/IPurchaseStorage.cs | 2 +- .../Implements/Worker/PurchaseStorage.cs | 8 ++++++-- .../HardwareShopRestApi/Controllers/PurchaseController.cs | 8 ++++++-- .../Views/Home/CreatePurchase.cshtml | 2 +- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs index 59fb61b..085fbfc 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs @@ -75,7 +75,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts model.PurchaseStatus = PurchaseStatus.Выдан; model.DatePurchase = DateTime.Now; CheckModel(model, false); - if (_purchaseStorage.Update(model) == null) + if (_purchaseStorage.Update(model, false) == null) { _logger.LogWarning("Change status operation failed"); return false; diff --git a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs index b140577..47283c8 100644 --- a/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs +++ b/HardwareShop/HardwareShopContracts/StoragesContracts/IPurchaseStorage.cs @@ -11,7 +11,7 @@ namespace HardwareShopContracts.StoragesContracts List GetReportFilteredList(PurchaseSearchModel model); PurchaseViewModel? GetElement(PurchaseSearchModel model); PurchaseViewModel? Insert(PurchaseBindingModel model); - PurchaseViewModel? Update(PurchaseBindingModel model); + PurchaseViewModel? Update(PurchaseBindingModel model, bool withParams = true); PurchaseViewModel? Delete(PurchaseBindingModel model); } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 513349f..cb094d9 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -101,7 +101,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker ?.GetViewModel; } - public PurchaseViewModel? Update(PurchaseBindingModel model) + public PurchaseViewModel? Update(PurchaseBindingModel model, bool withParams = true) { using var context = new HardwareShopDatabase(); using var transaction = context.Database.BeginTransaction(); @@ -117,7 +117,11 @@ namespace HardwareShopDatabaseImplement.Implements.Worker } purchase.Update(model); context.SaveChanges(); - purchase.UpdateGoods(context, model); + if (!withParams) { + transaction.Commit(); + return purchase.GetViewModel; + } + purchase.UpdateGoods(context, model); transaction.Commit(); return purchase.GetViewModel; } diff --git a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs index b459d3e..ec012c6 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs @@ -3,6 +3,7 @@ using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.SearchModels; using HardwareShopContracts.ViewModels; using HardwareShopDatabaseImplement.Models.Storekeeper; +using HardwareShopDataModels.Enums; using HardwareShopDataModels.Models; using HardwareShopRestApi.Controllers; using Microsoft.AspNetCore.Mvc; @@ -59,8 +60,7 @@ namespace HardwareShopRestApi.Controllers { for (int i = 0; i < model.PurchaseGoodsCounts.Count; i++) { - model.PurchaseGoods.Add(model.ListPurchaseGoods[i].Id, - (model.ListPurchaseGoods[i] as IGoodModel, model.PurchaseGoodsCounts[i])); + model.PurchaseGoods.Add(model.ListPurchaseGoods[i].Id,(model.ListPurchaseGoods[i] as IGoodModel, model.PurchaseGoodsCounts[i])); } _purchaseLogic.Create(model); } @@ -76,6 +76,10 @@ namespace HardwareShopRestApi.Controllers { try { + var oldModel = _purchaseLogic.ReadElement(new() { + Id = model.Id, + }); + model.Sum = oldModel.Sum; _purchaseLogic.DeliveryPurchase(model); } catch (Exception ex) diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml index a999da5..bff305e 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/CreatePurchase.cshtml @@ -106,7 +106,7 @@ contentType: 'application/json', data: JSON.stringify({ "Sum": parseFloat(totalSum.value), - "ListPurchaseGoods": goods + "ListPurchaseGoods": goods, "PurchaseGoodsCounts": counts }) } ).done(() => window.location.href = '/Home/Purchases') 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 03/15] 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 @@ - +
+ + + + + + + + + + + @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 From d3b455117e23d30048e21abe67002810038a5e7f 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: Wed, 17 May 2023 11:00:56 +0400 Subject: [PATCH 04/15] =?UTF-8?q?=D0=BF=D0=BE=D1=84=D0=B8=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BB=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=86=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA=D0=B5=20=D1=81=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=BA=D0=B8=20=D0=BA=20=D0=BF=D0=BE=D0=BA=D1=83?= =?UTF-8?q?=D0=BF=D0=BA=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BuildController.cs | 43 +++++++++++++++++-- .../Controllers/PurchaseController.cs | 18 +++++++- .../Controllers/HomeController.cs | 26 ++++++----- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs index 510cd82..9c3b129 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs @@ -18,12 +18,15 @@ namespace HardwareShopRestApi.Controllers { private readonly ILogger _logger; private readonly IBuildLogic _buildLogic; + private readonly IPurchaseLogic _purchaseLogic; - public BuildController(IBuildLogic buildLogic, ILogger logger) + public BuildController(IBuildLogic buildLogic, IPurchaseLogic purchaseLogic, ILogger logger) { _logger = logger; _buildLogic = buildLogic; - } + _purchaseLogic = purchaseLogic; + + } [HttpGet] public List? GetBuilds(int userId) @@ -112,7 +115,41 @@ namespace HardwareShopRestApi.Controllers } } - [HttpPost] + [HttpGet] + public bool LinkPurchase(int buildId, int purchaseId, int count) + { + try + { + var build = GetBuild(buildId);//APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); + var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId }); + purchase.Sum = purchase.Sum + build.Price * count; + build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count)); + Update(new BuildBindingModel + { + Id = buildId, + Price = build.Price, + BuildName = build.BuildName, + BuildPurchases = build.BuildPurchases + }); + + _purchaseLogic.Update(new PurchaseBindingModel + { + Id = purchase.Id, + Sum = purchase.Sum, + PurchaseStatus = purchase.PurchaseStatus, + DatePurchase = purchase.DatePurchase, + PurchaseGoods = purchase.PurchaseGoods, + }); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + + [HttpPost] public void DeleteBuild(BuildBindingModel model) { try diff --git a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs index ec012c6..4e7bd46 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/PurchaseController.cs @@ -40,11 +40,11 @@ namespace HardwareShopRestApi.Controllers } [HttpGet] - public PurchaseViewModel? GetPurchase(int id) + public PurchaseViewModel? GetPurchase(int purchaseId) { try { - return _purchaseLogic.ReadElement(new() { Id = id }); + return _purchaseLogic.ReadElement(new() { Id = purchaseId }); } catch (Exception ex) { @@ -89,6 +89,20 @@ namespace HardwareShopRestApi.Controllers } } + [HttpPost] + public void Update(PurchaseBindingModel model) + { + try + { + _purchaseLogic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных товара"); + throw; + } + } + [HttpPost] public void DeletePurchase(PurchaseBindingModel model) { diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index 48afca1..65cbe07 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -167,20 +167,24 @@ namespace HardwareShopWorkerApp.Controllers { 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 - }); + //APIClient.PostRequest("api/build/linkPurchase", new { buildId, purchaseId, count }); + APIClient.GetRequest($"api/build/linkPurchase?buildId={buildId}&purchaseId={purchaseId}&count={count}"); + + //var build = APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); + //var purchase = APIClient.GetRequest($"api/purchase/getpurchase?purchaseId={purchaseId}"); + //purchase.Sum = purchase.Sum + build.Price * count; + //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 + //}); + //APIClient.PostRequest("api/purchase/update", purchase); Response.Redirect("Builds"); } - [HttpPost] public void DeleteBuild(int deleteBuildId) { From 70f28e3c66449ce8820da891a7b91f75315153d3 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: Wed, 17 May 2023 11:54:30 +0400 Subject: [PATCH 05/15] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B1=D0=BE=D1=80?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=B8=D0=B7=20=D0=BF=D0=BE=D0=BA=D1=83=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BuildController.cs | 47 +++++++++++++++---- .../Controllers/HomeController.cs | 24 +++++++++- .../Views/Home/LinkPurchase.cshtml | 43 ++++++++++++++--- 3 files changed, 96 insertions(+), 18 deletions(-) diff --git a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs index 9c3b129..b53bbee 100644 --- a/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs +++ b/HardwareShop/HardwareShopRestApi/Controllers/BuildController.cs @@ -122,6 +122,7 @@ namespace HardwareShopRestApi.Controllers { var build = GetBuild(buildId);//APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId }); + if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false; purchase.Sum = purchase.Sum + build.Price * count; build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count)); Update(new BuildBindingModel @@ -131,15 +132,6 @@ namespace HardwareShopRestApi.Controllers BuildName = build.BuildName, BuildPurchases = build.BuildPurchases }); - - _purchaseLogic.Update(new PurchaseBindingModel - { - Id = purchase.Id, - Sum = purchase.Sum, - PurchaseStatus = purchase.PurchaseStatus, - DatePurchase = purchase.DatePurchase, - PurchaseGoods = purchase.PurchaseGoods, - }); return true; } catch (Exception ex) @@ -148,7 +140,44 @@ namespace HardwareShopRestApi.Controllers throw; } } + + [HttpGet] + public bool DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId) + { + try + { + var build = GetBuild(deleteBuildId);//APIClient.GetRequest($"api/build/getBuild?buildId={buildId}"); + var purchase = _purchaseLogic.ReadElement(new() { Id = deletePurchaseId }); + if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false; + purchase.Sum = purchase.Sum - build.Price * build.BuildPurchases[deletePurchaseId].Item2; + build.BuildPurchases.Remove(deletePurchaseId);//Add(purchaseId, (purchase as IPurchaseModel, count)); + + Update(new BuildBindingModel + { + Id = deleteBuildId, + Price = build.Price, + BuildName = build.BuildName, + BuildPurchases = build.BuildPurchases + }); + + _purchaseLogic.Update(new PurchaseBindingModel + { + Id = purchase.Id, + Sum = purchase.Sum, + PurchaseStatus = purchase.PurchaseStatus, + DatePurchase = purchase.DatePurchase, + PurchaseGoods = purchase.PurchaseGoods, + }); + return true; + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + [HttpPost] public void DeleteBuild(BuildBindingModel model) { diff --git a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs index 65cbe07..7f14abb 100644 --- a/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs +++ b/HardwareShop/HardwareShopWorkerApp/Controllers/HomeController.cs @@ -148,7 +148,7 @@ namespace HardwareShopWorkerApp.Controllers Response.Redirect("Builds"); } - [HttpPost] + [HttpGet] public void LinkBuildPurchase(int buildId, int purchaseId, int count) { if (APIClient.User == null) @@ -182,7 +182,7 @@ namespace HardwareShopWorkerApp.Controllers // BuildPurchases = build.BuildPurchases //}); //APIClient.PostRequest("api/purchase/update", purchase); - Response.Redirect("Builds"); + Response.Redirect($"LinkPurchase?buildId={buildId}"); } [HttpPost] @@ -423,5 +423,25 @@ namespace HardwareShopWorkerApp.Controllers ViewBag.Purchase = APIClient.GetRequest>($"api/purchase/getpurchases?userId={APIClient.User.Id}"); return View(APIClient.GetRequest>>($"api/build/GetBuildPurchase?buildId={buildId}")); } + + + [HttpPost] + public void DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId) + { + if (APIClient.User == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (deleteBuildId <= 0) + { + throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0"); + } + if (deletePurchaseId <= 0) + { + throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0"); + } + APIClient.GetRequest($"api/build/deleteLinkPurchase?deleteBuildId={deleteBuildId}&deletePurchaseId={deletePurchaseId}"); + Response.Redirect($"LinkPurchase?buildId={deleteBuildId}"); + } } } \ No newline at end of file diff --git a/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml b/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml index 82c39f2..710375a 100644 --- a/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml +++ b/HardwareShop/HardwareShopWorkerApp/Views/Home/LinkPurchase.cshtml @@ -53,12 +53,13 @@
- - +
@@ -71,7 +72,7 @@