ISEbd-21 Melnikov I. O. Lab work 02 Base #2

Closed
Igor-Melnikov wants to merge 5 commits from lab2 into lab1
6 changed files with 39 additions and 22 deletions
Showing only changes of commit 43c216879b - Show all commits

View File

@ -26,7 +26,7 @@ namespace BlacksmithWorkshopFileImplement
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.Create(x)!)!;
Orders = new List<Order>();
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{

View File

@ -2,7 +2,6 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement;
using BlacksmithWorkshopFileImplement.Models;
namespace BlacksmithWorkshopFileImplement.Implements

View File

@ -16,7 +16,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
public List<ManufactureViewModel> GetFullList()
{
return source.Manufactures
.Select(x => new ManufactureViewModel())
.Select(x => x.GetViewModel)
.ToList();
}
public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model)

View File

@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System.Collections.Generic;
namespace BlacksmithWorkshopFileImplement.Implements
{
@ -15,9 +16,16 @@ namespace BlacksmithWorkshopFileImplement.Implements
}
public List<OrderViewModel> GetFullList()
{
return source.Orders
.Select(x => new OrderViewModel())
List<OrderViewModel> orderList = new();
orderList = source.Orders
.Select(x => x.GetViewModel)
.ToList();
foreach (var order in orderList)
{
var manufactureName = source.Manufactures.SingleOrDefault(x => x.Id == order.ManufactureId)?.ManufactureName ?? string.Empty;
order.ManufactureName = manufactureName;
}
return orderList;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
@ -25,10 +33,17 @@ namespace BlacksmithWorkshopFileImplement.Implements
{
return new();
}
return source.Orders
List<OrderViewModel> orderList = new();
orderList = source.Orders
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
foreach (var order in orderList)
{
var manufactureName = source.Manufactures.SingleOrDefault(x => x.Id == order.ManufactureId)?.ManufactureName ?? string.Empty;
order.ManufactureName = manufactureName;
}
return orderList;
}
public OrderViewModel? GetElement(OrderSearchModel model)
{

View File

@ -76,16 +76,19 @@ namespace BlacksmithWorkshopFileImplement.Models
ManufactureComponents = ManufactureComponents
};
public XElement GetXElement => new
("Manufacture",
new XAttribute("Id", Id),
new XElement("ManufactureName", ManufactureName),
new XElement("Price", Price.ToString()),
new XElement("ManufactureComponents", Components.Select(x => new XElement
(
"ManufactureComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)
)).ToArray())
"Manufacture",
new XAttribute("Id", Id),
new XElement("ManufactureName", ManufactureName),
new XElement("Price", Price.ToString()),
new XElement("ManufactureComponents", Components.Select
(x => new XElement
(
"ManufactureComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value)
)
).ToArray())
);
}
}

View File

@ -41,12 +41,12 @@ namespace BlacksmithWorkshopFileImplement.Models
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureId = Convert.ToInt32(element.Attribute("ManufactureId")!.Value),
Count = Convert.ToInt32(element.Attribute("Count")!.Value),
Sum = Convert.ToDouble(element.Attribute("Sum")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Attribute("status")!.Value),
DateCreate = Convert.ToDateTime(element.Attribute("DateCreate")!.Value),
DateImplement = Convert.ToDateTime(element.Attribute("DateImplement")!.Value)
ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = Convert.ToDateTime(element.Element("DateImplement")!.Value)
};
}
public void Update(OrderBindingModel? model)
@ -75,7 +75,7 @@ namespace BlacksmithWorkshopFileImplement.Models
(
"Order",
new XAttribute("Id", Id),
new XElement("ManufactureID", ManufactureId),
new XElement("ManufactureId", ManufactureId),
new XElement("Count", Count),
new XElement("Sum", Sum),
new XElement("Status", (int)Status),