From abc2ef416421869f9623542d0a703def117fb310 Mon Sep 17 00:00:00 2001 From: Safgerd Date: Sat, 11 Mar 2023 21:06:17 +0400 Subject: [PATCH] =?UTF-8?q?LabWork01:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20(=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E?= =?UTF-8?q?=D1=81=D1=8C=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomobilePlant/FormCreateOrder.cs | 1 - .../BusinessLogics/OrderLogic.cs | 3 +-- .../BindingModels/OrderBindingModel.cs | 1 - .../Models/IOrderModel.cs | 1 - .../Implements/OrderStorage.cs | 26 ++++++++++++++----- .../Models/Order.cs | 4 --- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs b/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs index 49e5833..4114dd4 100644 --- a/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs +++ b/AutomobilePlant/AutomobilePlant/FormCreateOrder.cs @@ -102,7 +102,6 @@ namespace AutomobilePlant var operationResult = _logicO.CreateOrder(new OrderBindingModel { CarId = Convert.ToInt32(comboBoxCar.SelectedValue), - CarName = comboBoxCar.Text, Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs index ade6fec..f351853 100644 --- a/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/AutomobilePlant/AutomobilePlantBusinessLogic/BusinessLogics/OrderLogic.cs @@ -59,7 +59,6 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics { Id = viewModel.Id, CarId = viewModel.CarId, - CarName = viewModel.CarName, Status = viewModel.Status, DateCreate = viewModel.DateCreate, DateImplement = viewModel.DateImplement, @@ -67,7 +66,7 @@ namespace AutomobilePlantBusinessLogic.BusinessLogics Sum = viewModel.Sum }; - CheckModel(model); + CheckModel(model, false); if (model.Status + 1 != newStatus) { _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); diff --git a/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs index 6ae5855..a0e90ae 100644 --- a/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/BindingModels/OrderBindingModel.cs @@ -12,7 +12,6 @@ namespace AutomobilePlantContracts.BindingModels { public int Id { get; set; } public int CarId { get; set; } - public string CarName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs index 5cfd10e..3eec2ef 100644 --- a/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs +++ b/AutomobilePlant/AutomobilePlantDataModels/Models/IOrderModel.cs @@ -11,7 +11,6 @@ namespace AutomobilePlantDataModels.Models public interface IOrderModel : IId { int CarId { get; } - string CarName { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; } diff --git a/AutomobilePlant/AutomobilePlantListImplements/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantListImplements/Implements/OrderStorage.cs index 1b1c2a3..a999087 100644 --- a/AutomobilePlant/AutomobilePlantListImplements/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantListImplements/Implements/OrderStorage.cs @@ -30,7 +30,7 @@ namespace AutomobilePlantListImplements.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -47,7 +47,7 @@ namespace AutomobilePlantListImplements.Implements { if (order.Id == model.Id) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } } return result; @@ -58,7 +58,7 @@ namespace AutomobilePlantListImplements.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -79,7 +79,7 @@ namespace AutomobilePlantListImplements.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -89,7 +89,7 @@ namespace AutomobilePlantListImplements.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return GetViewModel(order); } } return null; @@ -103,10 +103,24 @@ namespace AutomobilePlantListImplements.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetViewModel(element); } } return null; } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var car in _source.Cars) + { + if (car.Id == order.CarId) + { + viewModel.CarName = car.CarName; + break; + } + } + return viewModel; + } } } diff --git a/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs b/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs index e354d48..c39798a 100644 --- a/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs +++ b/AutomobilePlant/AutomobilePlantListImplements/Models/Order.cs @@ -14,8 +14,6 @@ namespace AutomobilePlantListImplements.Models { public int CarId { get; private set; } - public string CarName { get; private set; } = string.Empty; - public int Count { get; private set; } public double Sum { get; private set; } @@ -37,7 +35,6 @@ namespace AutomobilePlantListImplements.Models return new Order { CarId = model.CarId, - CarName = model.CarName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -60,7 +57,6 @@ namespace AutomobilePlantListImplements.Models public OrderViewModel GetViewModel => new() { CarId = CarId, - CarName = CarName, Count = Count, Sum = Sum, DateCreate = DateCreate,