From 9af0c201fb03fac0ab2429b3e0ada8444f2e400c Mon Sep 17 00:00:00 2001 From: dasha Date: Sun, 12 Feb 2023 12:11:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBar/SushiBar/FormCreateOrder.cs | 1 - SushiBar/SushiBar/FormMain.cs | 18 ------------- .../BusinessLogics/OrderLogic.cs | 17 +++++++++++-- .../BindingModels/OrderBindingModel.cs | 1 - .../Implements/OrderStorage.cs | 25 ++++++++++++++----- .../SushiBarListImplement/Models/Order.cs | 4 --- 6 files changed, 34 insertions(+), 32 deletions(-) diff --git a/SushiBar/SushiBar/FormCreateOrder.cs b/SushiBar/SushiBar/FormCreateOrder.cs index 26d31f5..ebec9b3 100644 --- a/SushiBar/SushiBar/FormCreateOrder.cs +++ b/SushiBar/SushiBar/FormCreateOrder.cs @@ -88,7 +88,6 @@ namespace SushiBarView var operationResult = _logicO.CreateOrder(new OrderBindingModel { SushiId = Convert.ToInt32(comboBoxSushi.SelectedValue), - SushiName = comboBoxSushi.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/SushiBar/SushiBar/FormMain.cs b/SushiBar/SushiBar/FormMain.cs index fb523ea..aa6f30c 100644 --- a/SushiBar/SushiBar/FormMain.cs +++ b/SushiBar/SushiBar/FormMain.cs @@ -75,12 +75,6 @@ namespace SushiBarView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -106,12 +100,6 @@ namespace SushiBarView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { @@ -137,12 +125,6 @@ namespace SushiBarView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, - SushiId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["SushiId"].Value), - SushiName = dataGridView.SelectedRows[0].Cells["SushiName"].Value.ToString(), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), }); if (!operationResult) { diff --git a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs index 8b5ad72..31e9042 100644 --- a/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/SushiBar/SushiBarBusinessLogic/BusinessLogics/OrderLogic.cs @@ -75,14 +75,27 @@ namespace SushiBarBusinessLogic.BusinessLogics public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) { - CheckModel(model); - if (model.Status + 1 != newStatus) + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.Status + 1 != newStatus) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); return false; } model.Status = newStatus; + model.SushiId = viewModel.SushiId; + model.Count = viewModel.Count; + model.Sum = viewModel.Sum; + model.DateCreate = viewModel.DateCreate; if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now; + else + { + model.DateImplement = viewModel.DateImplement; + } + CheckModel(model); if (_orderStorage.Update(model) == null) { model.Status--; diff --git a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs index 65c3d70..9f761e8 100644 --- a/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/OrderBindingModel.cs @@ -6,7 +6,6 @@ namespace SushiBarContracts.BindingModels public class OrderBindingModel : IOrderModel { public int SushiId { get; set; } - public string SushiName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs index 9105ec6..c6b6e64 100644 --- a/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs +++ b/SushiBar/SushiBarListImplement/Implements/OrderStorage.cs @@ -18,7 +18,7 @@ namespace SushiBarListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -33,7 +33,7 @@ namespace SushiBarListImplement.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } return result; @@ -48,11 +48,24 @@ namespace SushiBarListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetViewModel(order); } } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var iceCream in _source.ListSushi) + { + if (iceCream.Id == order.SushiId) + { + viewModel.SushiName = iceCream.SushiName; + break; + } + } + return viewModel; + } public OrderViewModel? Insert(OrderBindingModel model) { model.Id = 1; @@ -69,7 +82,7 @@ namespace SushiBarListImplement.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) { @@ -78,7 +91,7 @@ namespace SushiBarListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -91,7 +104,7 @@ namespace SushiBarListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } return null; diff --git a/SushiBar/SushiBarListImplement/Models/Order.cs b/SushiBar/SushiBarListImplement/Models/Order.cs index a3bcd59..473e056 100644 --- a/SushiBar/SushiBarListImplement/Models/Order.cs +++ b/SushiBar/SushiBarListImplement/Models/Order.cs @@ -9,7 +9,6 @@ namespace SushiBarListImplement.Models { public int Id { get; private set; } public int SushiId { get; private set; } - public string SushiName { get; private set; } = string.Empty; public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; @@ -24,7 +23,6 @@ namespace SushiBarListImplement.Models return new Order { SushiId = model.SushiId, - SushiName = model.SushiName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -40,7 +38,6 @@ namespace SushiBarListImplement.Models return; } SushiId = model.SushiId; - SushiName = model.SushiName; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -51,7 +48,6 @@ namespace SushiBarListImplement.Models public OrderViewModel GetViewModel => new() { SushiId = SushiId, - SushiName = SushiName, Count = Count, Sum = Sum, DateCreate = DateCreate,