Исправление: вычисляемое поле теперь реально вычисляемое

This commit is contained in:
prodigygirl 2023-03-09 21:16:13 +04:00
parent 2a0061014a
commit f43443cb14
5 changed files with 24 additions and 17 deletions

View File

@ -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)
});

View File

@ -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;
}

View File

@ -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.Неизвестен;

View File

@ -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<OrderViewModel>();
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;
}
}
}

View File

@ -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,