Eliseev E.E. LabWork02_Hard #7

Closed
ElEgEv wants to merge 23 commits from LabWork02_Hard into LabWork01_Hard
4 changed files with 32 additions and 13 deletions
Showing only changes of commit e41554b69c - Show all commits

View File

@ -59,7 +59,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
source.Manufactures.Add(newManufacture);
source.SaveWorkPieces();
source.SaveManufactures();
return newManufacture.GetViewModel;
}
@ -74,7 +74,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
manufacture.Update(model);
source.SaveWorkPieces();
source.SaveManufactures();
return manufacture.GetViewModel;
}
@ -86,7 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
if (element != null)
{
source.Manufactures.Remove(element);
source.SaveWorkPieces();
source.SaveManufactures();
return element.GetViewModel;
}

View File

@ -23,7 +23,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => x.GetViewModel).ToList();
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
@ -33,7 +33,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
return new();
}
return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
@ -46,6 +46,24 @@ namespace BlacksmithWorkshopFileImplement.Implements
return source.Orders.FirstOrDefault(x =>(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
//для загрузки названий изделия в заказе
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
foreach(var manufacture in source.Manufactures)
{
if(manufacture.Id == order.ManufactureId)
{
viewModel.ManufactureName = manufacture.ManufactureName;
break;
}
}
return viewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
@ -58,9 +76,9 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
source.Orders.Add(newOrder);
source.SaveWorkPieces();
source.SaveOrders();
return newOrder.GetViewModel;
return GetViewModel(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
@ -73,9 +91,9 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
order.Update(model);
source.SaveWorkPieces();
source.SaveOrders();
return order.GetViewModel;
return GetViewModel(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
@ -85,9 +103,9 @@ namespace BlacksmithWorkshopFileImplement.Implements
if (element != null)
{
source.Orders.Remove(element);
source.SaveWorkPieces();
source.SaveOrders();
return element.GetViewModel;
return GetViewModel(element);
}
return null;

View File

@ -68,7 +68,7 @@ namespace BlacksmithWorkshopFileImplement.Models
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureName = element.Element("ManufactureName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureComponent").ToDictionary(
WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureWorkPieces").ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
@ -100,7 +100,7 @@ namespace BlacksmithWorkshopFileImplement.Models
new XElement("ManufactureName", ManufactureName),
new XElement("Price", Price.ToString()),
new XElement("ManufactureWorkPieces", WorkPieces.Select(
x => new XElement("ManufactureComponent",
x => new XElement("ManufactureWorkPieces",
new XElement("Key", x.Key),
new XElement("Value", x.Value))
).ToArray()));

View File

@ -95,6 +95,7 @@ namespace BlacksmithWorkshopFileImplement.Models
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));