Merge branch 'LabWork02_Base' into LabWork02_Hard

This commit is contained in:
Данила Мочалов 2023-03-10 19:39:05 +04:00
commit 7aa92dbb74
2 changed files with 21 additions and 19 deletions

View File

@ -26,8 +26,8 @@ namespace LawFirmFileImplement.Implements
{ {
return null; return null;
} }
return source.Orders return GetViewModel(source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -38,13 +38,13 @@ namespace LawFirmFileImplement.Implements
} }
return source.Orders return source.Orders
.Where(x => x.Id == model.Id) .Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel) .Select(x => GetViewModel(x))
.ToList(); .ToList();
} }
public List<OrderViewModel> GetFullList() 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) public OrderViewModel? Insert(OrderBindingModel model)
@ -57,7 +57,7 @@ namespace LawFirmFileImplement.Implements
} }
source.Orders.Add(newOrder); source.Orders.Add(newOrder);
source.SaveOrders(); source.SaveOrders();
return newOrder.GetViewModel; return GetViewModel(newOrder);
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
@ -69,7 +69,7 @@ namespace LawFirmFileImplement.Implements
} }
order.Update(model); order.Update(model);
source.SaveOrders(); source.SaveOrders();
return order.GetViewModel; return GetViewModel(order);
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
{ {
@ -80,7 +80,21 @@ namespace LawFirmFileImplement.Implements
} }
source.Orders.Remove(order); source.Orders.Remove(order);
source.SaveOrders(); 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;
} }
} }

View File

@ -15,8 +15,6 @@ namespace LawFirmFileImplement.Models
{ {
public int DocumentId { get; private set; } public int DocumentId { get; private set; }
public string DocumentName { get; private set; } = string.Empty;
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
@ -38,7 +36,6 @@ namespace LawFirmFileImplement.Models
return new Order return new Order
{ {
DocumentId = model.DocumentId, DocumentId = model.DocumentId,
DocumentName = model.DocumentName,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -57,7 +54,6 @@ namespace LawFirmFileImplement.Models
return new Order() return new Order()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
DocumentName = element.Element("DocumentName")!.Value,
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
@ -73,20 +69,13 @@ namespace LawFirmFileImplement.Models
{ {
return; return;
} }
DocumentId = model.DocumentId;
DocumentName = model.DocumentName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
Id = model.Id;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
DocumentId = DocumentId, DocumentId = DocumentId,
DocumentName = DocumentName,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
DateCreate = DateCreate, DateCreate = DateCreate,
@ -98,7 +87,6 @@ namespace LawFirmFileImplement.Models
public XElement GetXElement => new( public XElement GetXElement => new(
"Order", "Order",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("DocumentName", DocumentName),
new XElement("DocumentId", DocumentId.ToString()), new XElement("DocumentId", DocumentId.ToString()),
new XElement("Count", Count.ToString()), new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()), new XElement("Sum", Sum.ToString()),