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] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BD=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8=20=D1=83=D0=B4=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=D0=B1=D0=BE=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=20=D0=B8=D0=B7=20=D0=BF=D0=BE=D0=BA=D1=83=D0=BF=D0=BE?= =?UTF-8?q?=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 @@