From 43c216879b7cc708fe11edc93154330ffa95cd70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=BA=20=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Tue, 28 Feb 2023 17:41:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=87=D1=82=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=D0=B7=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B8=D1=8F=20=D0=B2=20=D0=B7=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=D0=B5,=20=D1=84=D0=B8=D0=BA=D1=81=20=D1=85=D0=BC=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 2 +- .../Implements/ComponentStorage.cs | 1 - .../Implements/ManufactureStorage.cs | 2 +- .../Implements/OrderStorage.cs | 21 ++++++++++++++++--- .../Models/Manufacture.cs | 21 +++++++++++-------- .../Models/Order.cs | 14 ++++++------- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs index 20e572c..a2b8f6c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/DataFileSingleton.cs @@ -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(); + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ComponentStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ComponentStorage.cs index 9390a9e..863c2e3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ComponentStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ComponentStorage.cs @@ -2,7 +2,6 @@ using BlacksmithWorkshopContracts.SearchModels; using BlacksmithWorkshopContracts.StoragesContracts; using BlacksmithWorkshopContracts.ViewModels; -using BlacksmithWorkshopFileImplement; using BlacksmithWorkshopFileImplement.Models; namespace BlacksmithWorkshopFileImplement.Implements diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs index 0676bca..7805dd5 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/ManufactureStorage.cs @@ -16,7 +16,7 @@ namespace BlacksmithWorkshopFileImplement.Implements public List GetFullList() { return source.Manufactures - .Select(x => new ManufactureViewModel()) + .Select(x => x.GetViewModel) .ToList(); } public List GetFilteredList(ManufactureSearchModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs index 81395ae..0e684e3 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Implements/OrderStorage.cs @@ -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 GetFullList() { - return source.Orders - .Select(x => new OrderViewModel()) + List 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 GetFilteredList(OrderSearchModel model) { @@ -25,10 +33,17 @@ namespace BlacksmithWorkshopFileImplement.Implements { return new(); } - return source.Orders + List 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) { diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs index 6d6cd12..2ae1b94 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Manufacture.cs @@ -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()) ); } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs index 9d00cbc..c39e6ef 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Order.cs @@ -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),