diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs index f506bb3..6810051 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs @@ -48,8 +48,7 @@ namespace FurnitureAssembly { var operationResult = _logicO.CreateOrder(new OrderBindingModel { - FurnitureId = Convert.ToInt32(comboBoxProduct.SelectedValue), - FurnitureName = comboBoxProduct.Text, + FurnitureId = Convert.ToInt32(comboBoxProduct.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs index bbe6d31..9bd343e 100644 --- a/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs +++ b/FurnitureAssembly/FurnitureAssemblyBusinessLogic/OrderLogic.cs @@ -139,11 +139,11 @@ namespace FurnitureAssemblyBusinessLogic throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); } _logger.LogInformation("Order. OrderId: { Id}. OrderStatus: {OrderStatus} DateCreate: {DateCreate} " + - "FurnitureId:{FurnitureId}. FurnitureName:{FurnitureName}. Count:{ Count}. Sum:{ Sum}. ", - model.Id, model.Status, model.DateCreate, model.FurnitureId, model.FurnitureName, model.Count, model.Sum); + "FurnitureId:{FurnitureId}. Count:{ Count}. Sum:{ Sum}. ", + model.Id, model.Status, model.DateCreate, model.FurnitureId, model.Count, model.Sum); } - private OrderBindingModel Find(OrderBindingModel model) + private OrderBindingModel? Find(OrderBindingModel model) { var modelView = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); if (modelView == null) @@ -155,7 +155,6 @@ namespace FurnitureAssemblyBusinessLogic model.Count = modelView.Count; model.Sum = modelView.Sum; model.FurnitureId = model.FurnitureId; - model.FurnitureName = modelView.FurnitureName; model.Status = modelView.Status; return model; } diff --git a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs index ea145e7..280e941 100644 --- a/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs +++ b/FurnitureAssembly/FurnitureAssemblyContracts/BindingModels/OrderBindingModel.cs @@ -12,7 +12,6 @@ namespace FurnitureAssemblyContracts.BindingModels { public int Id { get; set; } public int FurnitureId { get; set; } - public string FurnitureName { get; set; } = string.Empty; public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs index eeb359d..0e279ea 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/OrderStorage.cs @@ -26,7 +26,7 @@ namespace FurnitureAssemblyListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return element.GetViewModel; + return GetOrderViewModel(element); } } return null; @@ -43,7 +43,7 @@ namespace FurnitureAssemblyListImplement.Implements { if (model.Id.HasValue && order.Id == model.Id) { - return order.GetViewModel; + return GetOrderViewModel(order); } } return null; @@ -57,7 +57,7 @@ namespace FurnitureAssemblyListImplement.Implements { if (order.Id.Equals(model.Id)) { - result.Add(order.GetViewModel); + result.Add(GetOrderViewModel(order)); } } return result; @@ -68,7 +68,7 @@ namespace FurnitureAssemblyListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetOrderViewModel(order)); } return result; } @@ -89,7 +89,7 @@ namespace FurnitureAssemblyListImplement.Implements return null; } _source.Orders.Add(newOrder); - return newOrder.GetViewModel; + return GetOrderViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -99,10 +99,24 @@ namespace FurnitureAssemblyListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return order.GetViewModel; + return GetOrderViewModel(order); } } return null; } + + private OrderViewModel GetOrderViewModel(Order order) + { + OrderViewModel orderViewModel = order.GetViewModel; + + foreach (var furniture in _source.Furnitures) + { + if (furniture.Id == order.Id) + { + orderViewModel.FurnitureName = furniture.FurnitureName; + } + } + return orderViewModel; + } } } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs index 27101c3..570d67d 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Models/Order.cs @@ -16,8 +16,6 @@ namespace FurnitureAssemblyListImplement.Models { public int FurnitureId { get; private set; } - public string FurnitureName { get; private set; } = string.Empty; - public int Count { get; private set; } public double Sum { get; private set; } @@ -40,7 +38,6 @@ namespace FurnitureAssemblyListImplement.Models { Id = model.Id, FurnitureId = model.FurnitureId, - FurnitureName = model.FurnitureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -64,7 +61,6 @@ namespace FurnitureAssemblyListImplement.Models { Id = Id, FurnitureId = FurnitureId, - FurnitureName = FurnitureName, Count = Count, Sum = Sum, Status = Status,