Mochalov D.V. LabWork05_Hard #13
@ -26,8 +26,8 @@ namespace LawFirmFileImplement.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 LawFirmFileImplement.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 LawFirmFileImplement.Implements
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return newOrder.GetViewModel;
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -69,7 +69,7 @@ namespace LawFirmFileImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
return GetViewModel(order);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
@ -80,7 +80,21 @@ namespace LawFirmFileImplement.Implements
|
||||
}
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
foreach (var document in source.Documents)
|
||||
{
|
||||
if (document.Id == order.DocumentId)
|
||||
{
|
||||
viewModel.DocumentName = document.DocumentName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,6 @@ namespace LawFirmFileImplement.Models
|
||||
{
|
||||
public int DocumentId { get; private set; }
|
||||
|
||||
public string DocumentName { get; private set; } = string.Empty;
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
@ -38,7 +36,6 @@ namespace LawFirmFileImplement.Models
|
||||
return new Order
|
||||
{
|
||||
DocumentId = model.DocumentId,
|
||||
DocumentName = model.DocumentName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -57,7 +54,6 @@ namespace LawFirmFileImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
DocumentName = element.Element("DocumentName")!.Value,
|
||||
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
@ -73,20 +69,13 @@ namespace LawFirmFileImplement.Models
|
||||
{
|
||||
return;
|
||||
}
|
||||
DocumentId = model.DocumentId;
|
||||
DocumentName = model.DocumentName;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate;
|
||||
DateImplement = model.DateImplement;
|
||||
Id = model.Id;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
DocumentId = DocumentId,
|
||||
DocumentName = DocumentName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
@ -98,7 +87,6 @@ namespace LawFirmFileImplement.Models
|
||||
public XElement GetXElement => new(
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("DocumentName", DocumentName),
|
||||
new XElement("DocumentId", DocumentId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
|
Loading…
Reference in New Issue
Block a user