From eefb92d089d56ce4ae4c953b40aaea619ac75b01 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Feb 2023 09:17:10 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9C=D0=BE=D0=B4=D0=B5=D0=BB=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Models/Component.cs | 61 +++++++++ .../Models/Furniture.cs | 89 +++++++++++++ .../Models/Order.cs | 117 ++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs new file mode 100644 index 0000000..ce0dbca --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Component.cs @@ -0,0 +1,61 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System.Xml.Linq; + +namespace FurnitureAssemFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs new file mode 100644 index 0000000..6689a82 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Furniture.cs @@ -0,0 +1,89 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Models; +using System.Xml.Linq; + +namespace FurnitureAssemFileImplement.Models +{ + public class Furniture : IFurnitureModel + { + public int Id { get; private set; } + public string FurnitureName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _furnitureComponents = null; + public Dictionary FurnitureComponents + { + get + { + if (_furnitureComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _furnitureComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _furnitureComponents; + } + } + + public static Furniture? Create(FurnitureBindingModel model) + { + if (model == null) + { + return null; + } + return new Furniture() + { + Id = model.Id, + FurnitureName = model.FurnitureName, + Price = model.Price, + Components = model.FurnitureComponents.ToDictionary(x => x.Key, x => x.Value.Item2) + }; + } + + public static Furniture? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Furniture() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + FurnitureName = element.Element("FurnitureName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = element.Element("FurnitureComponents")!.Elements("FurnitureComponent").ToDictionary( + x => Convert.ToInt32(x.Element("Key")?.Value), + x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(FurnitureBindingModel model) + { + if (model == null) + { + return; + } + FurnitureName = model.FurnitureName; + Price = model.Price; + Components = model.FurnitureComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _furnitureComponents = null; + } + + public FurnitureViewModel GetViewModel => new() + { + Id = Id, + FurnitureName = FurnitureName, + Price = Price, + FurnitureComponents = FurnitureComponents + }; + public XElement GetXElement => new("Furniture", + new XAttribute("Id", Id), + new XElement("FurnitureName", FurnitureName), + new XElement("Price", Price.ToString()), + new XElement("FurnitureComponents", Components.Select( + x => new XElement("FurnitureComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs new file mode 100644 index 0000000..21000d3 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs @@ -0,0 +1,117 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemblyDataModels.Enums; +using FurnitureAssemblyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FurnitureAssemFileImplement.Models +{ + public class Order : IOrderModel + { + public int FurnitureId { get; private set; } + + public string FurnitureName { get; private set; } = string.Empty; + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + FurnitureId = model.FurnitureId, + FurnitureName = model.FurnitureName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.Value), + FurnitureName = element.Element("FurnitureName")!.Value, + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + FurnitureId = model.FurnitureId; + FurnitureName = model.FurnitureName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + FurnitureId = FurnitureId, + FurnitureName = FurnitureName, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("FurnitureId", FurnitureId), + new XElement("FurnitureName", FurnitureName), + 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())); + } +} From 940c4cbcdb3e0f3f6487acc4926938bed660df87 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Feb 2023 09:17:23 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ComponentStorage.cs | 92 +++++++++++++++++++ .../Implements/FurnitureStorage.cs | 88 ++++++++++++++++++ .../Implements/OrderStorage.cs | 89 ++++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Implements/ComponentStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Implements/FurnitureStorage.cs create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ComponentStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..e2d3450 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,92 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == + model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => + x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == + model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == + model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/FurnitureStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/FurnitureStorage.cs new file mode 100644 index 0000000..f9d26f2 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/FurnitureStorage.cs @@ -0,0 +1,88 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemFileImplement.Implements +{ + public class FurnitureStorage : IFurnitureStorage + { + private readonly DataFileSingleton source; + public FurnitureStorage() + { + source = DataFileSingleton.GetInstance(); + } + public FurnitureViewModel? GetElement(FurnitureSearchModel model) + { + if (string.IsNullOrEmpty(model.FurnitureName) && !model.Id.HasValue) + { + return null; + } + + return source.Furnitures.FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public List GetFilteredList(FurnitureSearchModel model) + { + if (string.IsNullOrEmpty(model.FurnitureName)) + { + return new(); + } + return source.Furnitures + .Where(x => x.FurnitureName.Contains(model.FurnitureName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Furnitures.Select(x => x.GetViewModel).ToList(); + } + + public FurnitureViewModel? Insert(FurnitureBindingModel model) + { + model.Id = source.Furnitures.Count > 0 ? source.Furnitures.Max(x => + x.Id) + 1 : 1; + var newFurniture = Furniture.Create(model); + if (newFurniture == null) + { + return null; + } + source.Furnitures.Add(newFurniture); + source.SaveFurnitures(); + return newFurniture.GetViewModel; + } + + public FurnitureViewModel? Update(FurnitureBindingModel model) + { + var furniture = source.Furnitures.FirstOrDefault(x => x.Id == model.Id); + if (furniture == null) + { + return null; + } + furniture.Update(model); + source.SaveFurnitures(); + return furniture.GetViewModel; + } + + public FurnitureViewModel? Delete(FurnitureBindingModel model) + { + var element = source.Furnitures.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Furnitures.Remove(element); + source.SaveFurnitures(); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..39ed910 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,89 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.SearchModels; +using FurnitureAssemblyContracts.StoragesContracts; +using FurnitureAssemblyContracts.ViewModels; +using FurnitureAssemFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureAssemFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).ToList(); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id.Equals(model.Id)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + return source.Orders + .FirstOrDefault(x => + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Orders.Remove(element); + source.SaveOrders(); + return element.GetViewModel; + } + return null; + } + } +} From 58255b68cf628a95e00283056a2ae0937121615b Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Feb 2023 09:17:44 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B5=D0=BA=D1=82=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20?= =?UTF-8?q?=D1=81=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataFileSingleton.cs | 56 +++++++++++++++++++ .../FurnitureAssemFileImplement.csproj | 14 +++++ 2 files changed, 70 insertions(+) create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/DataFileSingleton.cs create mode 100644 FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/DataFileSingleton.cs b/FurnitureAssembly/FurnitureAssemFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..7fb64b5 --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/DataFileSingleton.cs @@ -0,0 +1,56 @@ +using FurnitureAssemFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace FurnitureAssemFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string FurnitureFileName = "Furniture.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Furnitures { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveFurnitures() => SaveData(Furnitures, FurnitureFileName, "Furnitures", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Furnitures = LoadData(FurnitureFileName, "Furniture", x => Furniture.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, + Func selectFunction) + { + if (File.Exists(filename)) + { + return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, + string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, + data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj b/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj new file mode 100644 index 0000000..c0fa55b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssemFileImplement/FurnitureAssemFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + From 808ce1aea0538f3d746318736e5e4914fa4ffce8 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Feb 2023 09:19:16 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20?= =?UTF-8?q?Program?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FurnitureAssembly/FurnitureAssembly.sln | 8 +++++++- .../FurnitureAssembly/FurnitureAssembly.csproj | 1 + FurnitureAssembly/FurnitureAssembly/Program.cs | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssembly.sln b/FurnitureAssembly/FurnitureAssembly.sln index da3aa5d..51e7896 100644 --- a/FurnitureAssembly/FurnitureAssembly.sln +++ b/FurnitureAssembly/FurnitureAssembly.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyContracts" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyBusinessLogic", "FurnitureAssemblyBusinessLogic\FurnitureAssemblyBusinessLogic.csproj", "{B51952FD-5EB4-4A80-8598-7B1EC39CD34C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemblyListImplement", "FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj", "{6662252C-A676-4376-AA01-0ACC6AE5B217}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FurnitureAssemblyListImplement", "FurnitureAssemblyListImplement\FurnitureAssemblyListImplement.csproj", "{6662252C-A676-4376-AA01-0ACC6AE5B217}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureAssemFileImplement", "FurnitureAssemFileImplement\FurnitureAssemFileImplement.csproj", "{A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {6662252C-A676-4376-AA01-0ACC6AE5B217}.Debug|Any CPU.Build.0 = Debug|Any CPU {6662252C-A676-4376-AA01-0ACC6AE5B217}.Release|Any CPU.ActiveCfg = Release|Any CPU {6662252C-A676-4376-AA01-0ACC6AE5B217}.Release|Any CPU.Build.0 = Release|Any CPU + {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A6822E0E-DBF3-4DEA-A337-C6C64429C0DE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj index 243cc38..45d0618 100644 --- a/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj +++ b/FurnitureAssembly/FurnitureAssembly/FurnitureAssembly.csproj @@ -28,6 +28,7 @@ + \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/Program.cs b/FurnitureAssembly/FurnitureAssembly/Program.cs index 2cc7ecb..bac7790 100644 --- a/FurnitureAssembly/FurnitureAssembly/Program.cs +++ b/FurnitureAssembly/FurnitureAssembly/Program.cs @@ -1,11 +1,10 @@ using FurnitureAssemblyBusinessLogic; using FurnitureAssemblyContracts.BusinessLogicsContarcts; using FurnitureAssemblyContracts.StoragesContracts; -using FurnitureAssemblyListImplement.Implements; +using FurnitureAssemFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using System.Drawing; namespace FurnitureAssembly { @@ -26,6 +25,7 @@ namespace FurnitureAssembly ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); + } private static void ConfigureServices(ServiceCollection services) From 0c29f24758a8cce62ab26d500798e2f176f045d3 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sat, 11 Mar 2023 10:14:56 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5:=20=D0=B2=D1=8B=D1=87=D0=B8=D1=81?= =?UTF-8?q?=D0=BB=D1=8F=D0=B5=D0=BC=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=20=D0=B8=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B0=D0=BF=D0=B4?= =?UTF-8?q?=D0=B5=D0=B9=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 32 +++++++++++++------ .../Models/Order.cs | 10 +----- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs index 39ed910..0941610 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; namespace FurnitureAssemFileImplement.Implements { @@ -21,7 +22,7 @@ namespace FurnitureAssemFileImplement.Implements public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => GetOrderViewModel(x)).ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -32,7 +33,7 @@ namespace FurnitureAssemFileImplement.Implements } return source.Orders .Where(x => x.Id.Equals(model.Id)) - .Select(x => x.GetViewModel) + .Select(x => GetOrderViewModel(x)) .ToList(); } @@ -42,11 +43,10 @@ namespace FurnitureAssemFileImplement.Implements { return null; } - - return source.Orders + var order = source.Orders .FirstOrDefault(x => - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + (model.Id.HasValue && x.Id == model.Id)); + return GetOrderViewModel(order); } public OrderViewModel? Insert(OrderBindingModel model) @@ -59,7 +59,7 @@ namespace FurnitureAssemFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return GetOrderViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -71,7 +71,7 @@ namespace FurnitureAssemFileImplement.Implements } order.Update(model); source.SaveOrders(); - return order.GetViewModel; + return GetOrderViewModel(order); } public OrderViewModel? Delete(OrderBindingModel model) @@ -81,9 +81,23 @@ namespace FurnitureAssemFileImplement.Implements { source.Orders.Remove(element); source.SaveOrders(); - return element.GetViewModel; + return GetOrderViewModel(element); } return null; } + + private OrderViewModel GetOrderViewModel(Order order) + { + OrderViewModel orderViewModel = order.GetViewModel; + + foreach (var furniture in source.Furnitures) + { + if (furniture.Id == order.Id) + { + orderViewModel.FurnitureName = furniture.FurnitureName; + } + } + return orderViewModel; + } } } diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs index 21000d3..184a929 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Models/Order.cs @@ -41,7 +41,6 @@ namespace FurnitureAssemFileImplement.Models { Id = model.Id, FurnitureId = model.FurnitureId, - FurnitureName = model.FurnitureName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -60,7 +59,6 @@ namespace FurnitureAssemFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.Value), - FurnitureName = element.Element("FurnitureName")!.Value, Count = Convert.ToInt32(element.Element("Count")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), @@ -83,12 +81,8 @@ namespace FurnitureAssemFileImplement.Models { return; } - FurnitureId = model.FurnitureId; - FurnitureName = model.FurnitureName; - Count = model.Count; - Sum = model.Sum; + Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } @@ -96,7 +90,6 @@ namespace FurnitureAssemFileImplement.Models { Id = Id, FurnitureId = FurnitureId, - FurnitureName = FurnitureName, Count = Count, Sum = Sum, Status = Status, @@ -107,7 +100,6 @@ namespace FurnitureAssemFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("FurnitureId", FurnitureId), - new XElement("FurnitureName", FurnitureName), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), From 071daf691882f4723eebe69a1df9eab7da0def6b Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 12 Mar 2023 10:25:45 +0400 Subject: [PATCH 6/6] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5....................?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FurnitureAssemFileImplement/Implements/OrderStorage.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs index 0941610..3875178 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/OrderStorage.cs @@ -92,7 +92,7 @@ namespace FurnitureAssemFileImplement.Implements foreach (var furniture in source.Furnitures) { - if (furniture.Id == order.Id) + if (furniture.Id == order.FurnitureId) { orderViewModel.FurnitureName = furniture.FurnitureName; }