From 623a3dde7e3bb34852a9a2970bb0553a54861fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F=20=D0=A4=D0=B5=D0=B4=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sat, 1 Jun 2024 03:16:34 +0400 Subject: [PATCH] Order sum fix --- .../Models/Order.cs | 3 ++- .../Controllers/MainController.cs | 15 ++++++++++++--- .../Views/Home/EditOrder.cshtml | 2 +- .../Views/Home/OrderView.cshtml | 2 +- .../Views/Shared/_Layout.cshtml | 2 +- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs index f80844e..3eefb25 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/Order.cs @@ -87,11 +87,12 @@ namespace ElectronicsShopDataBaseImplement.Models context.SaveChanges(); } var order = context.Orders.First(x => x.ID == model.ID); + order.Sum = model.Sum; foreach (var op in model.ProductList) { context.OrderProducts.Add(new OrderProduct { _order = order, _product = context.Products.First(x => x.ID == op.Key), - Count = op.Value.Item2 + Count = op.Value.Item2, }); context.SaveChanges(); } diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index 4940f28..260e37f 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -161,7 +161,7 @@ namespace ElectronicsShopRestAPI.Controllers { ClientID = view.ClientID, DateCreate = view.DateCreate, ProductList = _productlist, - //sum + Sum = Calc(_productlist) }; var operationResult = _order.Update(model); if (!operationResult) { @@ -198,8 +198,8 @@ namespace ElectronicsShopRestAPI.Controllers { ID = _orderId, ClientID = view.ClientID, DateCreate = view.DateCreate, - ProductList = _productlist - //sum + ProductList = _productlist, + Sum = Calc(_productlist) }; var operationResult = _order.DeleteProduct(model); if (!operationResult) { @@ -211,5 +211,14 @@ namespace ElectronicsShopRestAPI.Controllers { throw; } } + + [HttpPost] + public double Calc(Dictionary _productlist) { + double ans = 0; + foreach (var item in _productlist) { + ans += item.Value.Item1.Price * item.Value.Item2; + } + return ans; + } } } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml index 0e523e9..fa75e9a 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/EditOrder.cshtml @@ -75,7 +75,7 @@ diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml index b8f6b52..717fadf 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/OrderView.cshtml @@ -76,7 +76,7 @@ diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml index a2bd948..23f23eb 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Shared/_Layout.cshtml @@ -12,7 +12,7 @@