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] 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')