diff --git a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs index b486a52..84d4976 100644 --- a/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs +++ b/ElectronicsShop/ElectronicsShopBusinessLogic/BusinessLogic/PaymeantLogic.cs @@ -89,7 +89,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) { CheckModel(model, false); model.PayOption = paymeantOption; - if (_storage.UpdatePay == null) { + if (_storage.UpdatePay(model) == null) { _logger.LogWarning("update operation failed"); return false; } diff --git a/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs b/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs index 52575c0..3a518f6 100644 --- a/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs +++ b/ElectronicsShop/ElectronicsShopContracts/SearchModels/PaymeantSearchModel.cs @@ -10,7 +10,6 @@ namespace ElectronicsShopContracts.SearchModels { public int? ID { get; set; } public int? OrderID { get; set; } - public double? SumPay { get; set; } public int? ClientID { get; set; } public DateTime? DateFrom{ get; set; } public DateTime? DateTo { get; set; } diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs index a8eda0b..0a513b2 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/OrderStorage.cs @@ -32,6 +32,7 @@ namespace ElectronicsShopDataBaseImplement.Implements if (order == null) { return null; } + order.Update(model); order.UpdateProducts(context, model); transcation.Commit(); return order.GetViewModel; diff --git a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs index 0f6559c..c71c057 100644 --- a/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs +++ b/ElectronicsShop/ElectronicsShopDataBaseImplement/Implements/PaymeantStorage.cs @@ -25,7 +25,6 @@ namespace ElectronicsShopDataBaseImplement.Implements { return newPayment.GetViewModel; } - // todo тут должен меняться статус оплаты public PaymeantViewModel? UpdatePay(PaymeantBindingModel model) { using var context = new Database(); var paymeant = context.Paymeants.FirstOrDefault(x => x.ID == model.ID); @@ -39,7 +38,11 @@ namespace ElectronicsShopDataBaseImplement.Implements { public PaymeantViewModel? GetElement(PaymeantSearchModel model) { using var context = new Database(); - return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel; + if (model.OrderID.HasValue) { + return context.Paymeants.FirstOrDefault(x => x.OrderID == model.OrderID)?.GetViewModel; + } + return context.Paymeants + .FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel; } public List GetFillteredList(PaymeantSearchModel model) { @@ -50,8 +53,15 @@ namespace ElectronicsShopDataBaseImplement.Implements { .Select(x => x.GetViewModel) .ToList(); } + else if (model.ClientID.HasValue) { + + return context.Paymeants + .Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList(); + } return context.Paymeants - .Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList(); + .Where(x => x.OrderID == model.OrderID) + .Select(x => x.GetViewModel) + .ToList(); } public List? GetFullList() { diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs index d5a0eaa..abe56ab 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/ClientController.cs @@ -8,6 +8,7 @@ using ElectronicsShopContracts.SearchModels; using ElectronicsShopContracts.ViewModels; using ElectronicsShopDataBaseImplement.Models; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Identity.Client; using MigraDoc.Rendering; @@ -74,19 +75,64 @@ namespace ElectronicsShopRestAPI.Controllers { [HttpPost] public void CreatePaymeant (PaymeantBindingModel model) { try { - var products = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID })?.ProductList; + if (_payLogic.ReadList(new PaymeantSearchModel { OrderID = model.OrderID })?.Count > 0) { + var order = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID }); - if (products == null) { - throw new Exception("Ошибка получения товаров"); + if (order == null) { + throw new Exception("Ошибка получения данных"); + } + + _orderLogic.Update(new OrderBindingModel { + ID = order.ID, + ClientID = order.ClientID, + DateCreate = order.DateCreate, + Sum = order.Sum - model.SumPayment, + ProductList = order.ProductList, + }); + + var payemeant = _payLogic.ReadElement(new PaymeantSearchModel { OrderID = model.OrderID }) + ?? throw new Exception("Ошибка получения оплаты"); + payemeant.SumPayment += model.SumPayment; + + _payLogic.SetStatus(new PaymeantBindingModel { + ID = payemeant.ID, + OrderID = payemeant.OrderID, + SumPayment = payemeant.SumPayment, + PayOption = payemeant.PayOption, + ClientID = payemeant.ClientID, + DatePaymeant = payemeant.DatePaymeant, + PayProductList = payemeant.PayProductList, + }, model.PayOption); } + else { + var products = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID })?.ProductList; - model.PayProductList = products; - _payLogic.CreatePay(model); + if (products == null) { + throw new Exception("Ошибка получения данных"); + } + + model.PayProductList = products; + _payLogic.CreatePay(model); + } if (model.PayOption == 0) { - _orderLogic.Delete(new OrderBindingModel { ID = model.OrderID}); + _orderLogic.Delete(new OrderBindingModel { ID = model.OrderID }); + } + else { + var order = _orderLogic.ReadElement(new OrderSearchModel { ID = model.OrderID }); + + if (order == null) { + throw new Exception("Ошибка получения данных"); + } + + _orderLogic.Update(new OrderBindingModel { + ID = order.ID, + ClientID = order.ClientID, + DateCreate = order.DateCreate, + Sum = order.Sum - model.SumPayment, + ProductList = order.ProductList, + }); } - } catch (Exception ex) { _logger.LogError(ex, "Ошибка создания оплаты"); diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs index a043b3b..d06fa21 100644 --- a/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs +++ b/ElectronicsShop/ElectronicsShopRestAPI/Controllers/MainController.cs @@ -82,9 +82,12 @@ namespace ElectronicsShopRestAPI.Controllers { } [HttpGet] - public OrderViewModel? GetOrder(int _clientID) { + public OrderViewModel? GetOrder(int? _clientID, int? _orderID) { try { - return _order.ReadElement(new OrderSearchModel { ClientID = _clientID }); + if (_orderID.HasValue) { + return _order.ReadElement(new OrderSearchModel { ID = _orderID }); + } + return _order.ReadElement(new OrderSearchModel { ClientID = _clientID }); } catch (Exception ex) { _logger.LogError(ex, $"Ошибка получения данных clientid = {_clientID}"); @@ -245,4 +248,4 @@ namespace ElectronicsShopRestAPI.Controllers { } } } -} +} \ No newline at end of file diff --git a/ElectronicsShop/ElectronicsShopRestAPI/Report b/ElectronicsShop/ElectronicsShopRestAPI/Report index ee30878..9d1c400 100644 Binary files a/ElectronicsShop/ElectronicsShopRestAPI/Report and b/ElectronicsShop/ElectronicsShopRestAPI/Report differ diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs index 78b0466..08d16bb 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Controllers/HomeController.cs @@ -235,7 +235,10 @@ namespace ElectronicsShopUserApp.Controllers { _productList.Add(product.ID, (product, count)); } - (int, Dictionary) tuple = (id, _productList); + double sum = APIClient.GetRequset($"api/main/getorder?_orderid={id}").Sum; + + + (double ,int, Dictionary) tuple = (sum, id, _productList); return View(tuple); } diff --git a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Payment.cshtml b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Payment.cshtml index 8d0740c..bb49740 100644 --- a/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Payment.cshtml +++ b/ElectronicsShop/ElectronicsShopShopClientApp/Views/Home/Payment.cshtml @@ -1,7 +1,7 @@ @using ElectronicsShopContracts.ViewModels @using ElectronicsShopDataModels.Models -@model (int, Dictionary) +@model (double, int, Dictionary) @{ ViewData["Title"] = "Payment"; @@ -15,7 +15,7 @@
- +
@@ -29,7 +29,7 @@
Сумма к оплате:
- +
@@ -51,7 +51,7 @@ - @foreach (var item in Model.Item2) + @foreach (var item in Model.Item3) { @@ -80,25 +80,4 @@
- - - \ No newline at end of file