Minhasapov R.H. LabWork02_Hard #10

Closed
safgerd wants to merge 10 commits from LabWork02_Hard into LabWork01_Hard
2 changed files with 19 additions and 13 deletions
Showing only changes of commit 818c4db5d6 - Show all commits

View File

@ -26,8 +26,8 @@ namespace AutomobilePlantFileImplement.Implements
{
return null;
}
return source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
return GetViewModel(source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -38,13 +38,13 @@ namespace AutomobilePlantFileImplement.Implements
}
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.Select(x => GetViewModel(x))
.ToList();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => x.GetViewModel).ToList();
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? Insert(OrderBindingModel model)
@ -57,7 +57,7 @@ namespace AutomobilePlantFileImplement.Implements
}
source.Orders.Add(newOrder);
source.SaveOrders();
return newOrder.GetViewModel;
return GetViewModel(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
@ -69,8 +69,9 @@ namespace AutomobilePlantFileImplement.Implements
}
order.Update(model);
source.SaveOrders();
return order.GetViewModel;
return GetViewModel(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
@ -80,7 +81,18 @@ namespace AutomobilePlantFileImplement.Implements
}
source.Orders.Remove(order);
source.SaveOrders();
return order.GetViewModel;
return GetViewModel(order);
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var car = source.Cars.FirstOrDefault(x => x.Id == order.CarId);
if (car != null)
{
viewModel.CarName = car.CarName;
}
return viewModel;
}
}
}

View File

@ -15,8 +15,6 @@ namespace AutomobilePlantFileImplement.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; }
@ -38,7 +36,6 @@ namespace AutomobilePlantFileImplement.Models
return new Order
{
CarId = model.CarId,
CarName = model.CarName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -57,7 +54,6 @@ namespace AutomobilePlantFileImplement.Models
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
CarName = element.Element("CarName")!.Value,
CarId = Convert.ToInt32(element.Element("CarId")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
@ -80,7 +76,6 @@ namespace AutomobilePlantFileImplement.Models
public OrderViewModel GetViewModel => new()
{
CarId = CarId,
CarName = CarName,
Count = Count,
Sum = Sum,
DateCreate = DateCreate,
@ -92,7 +87,6 @@ namespace AutomobilePlantFileImplement.Models
public XElement GetXElement => new(
"Order",
new XAttribute("Id", Id),
new XElement("CarName", CarName),
new XElement("CarId", CarId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),