From 4cc264503a4566ee313f88f33649a5777b635dd0 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Tue, 12 Mar 2024 21:53:02 +0400 Subject: [PATCH 1/3] First --- .../AbstractLawFirmFileImplement.csproj | 14 +++ .../DataFileSingleton.cs | 62 +++++++++++ .../Implements/ComponentStorage.cs | 90 +++++++++++++++ .../Models/Component.cs | 64 +++++++++++ .../Models/Document.cs | 103 ++++++++++++++++++ LawFirm/LawFirm.sln | 10 +- LawFirm/LawFirmView/LawFirmView.csproj | 1 + 7 files changed, 342 insertions(+), 2 deletions(-) create mode 100644 LawFirm/AbstractLawFirmFileImpliment/AbstractLawFirmFileImplement.csproj create mode 100644 LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Models/Component.cs create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs diff --git a/LawFirm/AbstractLawFirmFileImpliment/AbstractLawFirmFileImplement.csproj b/LawFirm/AbstractLawFirmFileImpliment/AbstractLawFirmFileImplement.csproj new file mode 100644 index 0000000..f54052f --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/AbstractLawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs new file mode 100644 index 0000000..20958a4 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using AbstractLawFirmFileImplement.Models; + +namespace AbstractLawFirmFileImpliment +{ + internal class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string ProductFileName = "Product.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Documents { 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 SaveProducts() => SaveData(Products, ProductFileName, + "Products", x => x.GetXElement); + public void SaveOrders() { } + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => + Component.Create(x)!)!; + Documents = LoadData(ProductFileName, "Product", x => + Document.Create(x)!)!; + Orders = new List(); + } + 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/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs new file mode 100644 index 0000000..c07e161 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs @@ -0,0 +1,90 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmFileImplement.Models; +using AbstractLawFirmFileImpliment; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmFileImplement.Implements +{ + public class ComponentStorage + { + 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/LawFirm/AbstractLawFirmFileImpliment/Models/Component.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Component.cs new file mode 100644 index 0000000..2ff458b --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Component.cs @@ -0,0 +1,64 @@ +using AbstractLawFirmContracts.BindingModels.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractLawFirmFileImplement.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/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs new file mode 100644 index 0000000..4f52077 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs @@ -0,0 +1,103 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using AbstractLawFirmFileImpliment; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractLawFirmFileImplement.Models +{ + public class Document : IDocumentModel + { + public int Id { get; private set; } + public string DocumentName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _productComponents = + null; + public Dictionary ProductComponents + { + get + { + if (_productComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _productComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _productComponents; + } + } + public static Document? Create(DocumentBindingModel model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Components = model.DocumentComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Document? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Document() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("ProductName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("ProductComponents")!.Elements("ProductComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(DocumentBindingModel model) + { + if (model == null) + { + return; + } + DocumentName = model.DocumentName; + Price = model.Price; + Components = model.DocumentComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _productComponents = null; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentComponents = ProductComponents + }; + public XElement GetXElement => new("Product", + new XAttribute("Id", Id), + new XElement("ProductName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("ProductComponents", Components.Select(x => + new XElement("ProductComponent", + + new XElement("Key", x.Key), + + new XElement("Value", x.Value))) + + .ToArray())); + + public Dictionary DocumentComponents => throw new NotImplementedException(); + } +} diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 09da4ff..e41b11c 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -9,9 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmDataModels", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmContracts", "AbstractLawFirmContracts\AbstractLawFirmContracts\AbstractLawFirmContracts.csproj", "{C0155B2E-5974-4835-996B-6FDF0F5BC06B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmBusinessLogic", "AbstractLawFirmBusinessLogic\AbstractLawFirmBusinessLogic.csproj", "{E48808B1-5381-4774-97B6-CDB107DCF98C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmBusinessLogic", "AbstractLawFirmBusinessLogic\AbstractLawFirmBusinessLogic.csproj", "{E48808B1-5381-4774-97B6-CDB107DCF98C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmListImplement", "AbstractLawFirmListImplement\AbstractLawFirmListImplement.csproj", "{86D5FC6F-B262-44A0-9D30-970F9EA93E0A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AbstractLawFirmListImplement", "AbstractLawFirmListImplement\AbstractLawFirmListImplement.csproj", "{86D5FC6F-B262-44A0-9D30-970F9EA93E0A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractLawFirmFileImplement", "AbstractLawFirmFileImpliment\AbstractLawFirmFileImplement.csproj", "{8AF960C2-208F-4B7B-9F8B-36B63446B6B7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Debug|Any CPU.Build.0 = Debug|Any CPU {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Release|Any CPU.ActiveCfg = Release|Any CPU {86D5FC6F-B262-44A0-9D30-970F9EA93E0A}.Release|Any CPU.Build.0 = Release|Any CPU + {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8AF960C2-208F-4B7B-9F8B-36B63446B6B7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmView/LawFirmView.csproj b/LawFirm/LawFirmView/LawFirmView.csproj index b6cfc13..c62edf7 100644 --- a/LawFirm/LawFirmView/LawFirmView.csproj +++ b/LawFirm/LawFirmView/LawFirmView.csproj @@ -15,6 +15,7 @@ + -- 2.25.1 From d242771ff1ec38c7631f76d34759f40679fc2cd5 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 13 Mar 2024 01:12:49 +0400 Subject: [PATCH 2/3] second --- .../DataFileSingleton.cs | 16 ++-- .../Implements/DocumentStorage.cs | 84 +++++++++++++++++ .../Implements/OrderStorage.cs | 94 +++++++++++++++++++ .../Models/Document.cs | 41 ++++---- .../Models/Order.cs | 94 +++++++++++++++++++ 5 files changed, 297 insertions(+), 32 deletions(-) create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Implements/DocumentStorage.cs create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs create mode 100644 LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs diff --git a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs index 20958a4..a220336 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/DataFileSingleton.cs @@ -27,16 +27,16 @@ namespace AbstractLawFirmFileImpliment } public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); - public void SaveProducts() => SaveData(Products, ProductFileName, - "Products", x => x.GetXElement); - public void SaveOrders() { } + public void SaveDocuments() => SaveData(Documents, ProductFileName, + "Documents", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, + "Orders", x => x.GetXElement); private DataFileSingleton() { - Components = LoadData(ComponentFileName, "Component", x => - Component.Create(x)!)!; - Documents = LoadData(ProductFileName, "Product", x => - Document.Create(x)!)!; - Orders = new List(); + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Documents = LoadData(ProductFileName, "Document", x => Document.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) diff --git a/LawFirm/AbstractLawFirmFileImpliment/Implements/DocumentStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/DocumentStorage.cs new file mode 100644 index 0000000..9252324 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/DocumentStorage.cs @@ -0,0 +1,84 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmFileImplement.Models; +using AbstractLawFirmFileImpliment; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmFileImplement.Implements +{ + public class DocumentStorage : IDocumentStorage + { + private readonly DataFileSingleton source; + + public DocumentStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public DocumentViewModel? GetElement(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue) + { + return null; + } + return source.Documents.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(DocumentSearchModel model) + { + if (string.IsNullOrEmpty(model.DocumentName)) + { + return new(); + } + return source.Documents.Where(x => x.DocumentName.Contains(model.DocumentName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Documents.Select(x => x.GetViewModel).ToList(); + } + + public DocumentViewModel? Insert(DocumentBindingModel model) + { + model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1; + var newDoc = Document.Create(model); + if (newDoc == null) + { + return null; + } + source.Documents.Add(newDoc); + source.SaveDocuments(); + return newDoc.GetViewModel; + } + + public DocumentViewModel? Update(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + public DocumentViewModel? Delete(DocumentBindingModel model) + { + var document = source.Documents.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + source.Documents.Remove(document); + source.SaveDocuments(); + return document.GetViewModel; + } + + } +} \ No newline at end of file diff --git a/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs new file mode 100644 index 0000000..2674094 --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/OrderStorage.cs @@ -0,0 +1,94 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmFileImplement.Models; +using AbstractLawFirmFileImpliment; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); + } + + 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 GetViewModel(newOrder); + } + + 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 GetViewModel(order); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + source.Orders.Remove(order); + source.SaveOrders(); + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId); + if (document != null) + { + viewModel.DocumentName = document.DocumentName; + } + return viewModel; + } + } +} \ No newline at end of file diff --git a/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs index 4f52077..3aacd44 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Document.cs @@ -17,20 +17,19 @@ namespace AbstractLawFirmFileImplement.Models public string DocumentName { get; private set; } = string.Empty; public double Price { get; private set; } public Dictionary Components { get; private set; } = new(); - private Dictionary? _productComponents = - null; - public Dictionary ProductComponents + private Dictionary? _documentComponents = null; + public Dictionary DocumentComponents { get { - if (_productComponents == null) + if (_documentComponents == null) { var source = DataFileSingleton.GetInstance(); - _productComponents = Components.ToDictionary(x => x.Key, y => + _documentComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); } - return _productComponents; + return _documentComponents; } } public static Document? Create(DocumentBindingModel model) @@ -57,10 +56,10 @@ namespace AbstractLawFirmFileImplement.Models return new Document() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - DocumentName = element.Element("ProductName")!.Value, + DocumentName = element.Element("DocumentName")!.Value, Price = Convert.ToDouble(element.Element("Price")!.Value), Components = - element.Element("ProductComponents")!.Elements("ProductComponent") + element.Element("DocumentComponents")!.Elements("DocumentComponent") .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) @@ -76,28 +75,22 @@ namespace AbstractLawFirmFileImplement.Models Price = model.Price; Components = model.DocumentComponents.ToDictionary(x => x.Key, x => x.Value.Item2); - _productComponents = null; + _documentComponents = null; } public DocumentViewModel GetViewModel => new() { Id = Id, DocumentName = DocumentName, Price = Price, - DocumentComponents = ProductComponents + DocumentComponents = DocumentComponents }; - public XElement GetXElement => new("Product", - new XAttribute("Id", Id), - new XElement("ProductName", DocumentName), - new XElement("Price", Price.ToString()), - new XElement("ProductComponents", Components.Select(x => - new XElement("ProductComponent", - - new XElement("Key", x.Key), - - new XElement("Value", x.Value))) - - .ToArray())); - - public Dictionary DocumentComponents => throw new NotImplementedException(); + public XElement GetXElement => new("Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentComponents", Components.Select(x => + new XElement("DocumentComponent", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); } } diff --git a/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs b/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs new file mode 100644 index 0000000..fe2eb6f --- /dev/null +++ b/LawFirm/AbstractLawFirmFileImpliment/Models/Order.cs @@ -0,0 +1,94 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Enums; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace AbstractLawFirmFileImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int DocumentId { get; private set; } + 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; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + DocumentId = model.DocumentId, + 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; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), + DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Id = model.Id; + DocumentId = model.DocumentId; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + DocumentId = DocumentId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("DocumentId", DocumentId.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()) + ); + } +} -- 2.25.1 From b937f4be4f0de1975639d2492c5b207e64f18b62 Mon Sep 17 00:00:00 2001 From: GokaPek Date: Wed, 13 Mar 2024 09:35:22 +0400 Subject: [PATCH 3/3] final --- .../Implements/ComponentStorage.cs | 3 ++- LawFirm/LawFirmView/Program.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs b/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs index c07e161..b0bbb22 100644 --- a/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs +++ b/LawFirm/AbstractLawFirmFileImpliment/Implements/ComponentStorage.cs @@ -1,5 +1,6 @@ using AbstractLawFirmContracts.BindingModels.BindingModels; using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; using AbstractLawFirmContracts.ViewModels; using AbstractLawFirmFileImplement.Models; using AbstractLawFirmFileImpliment; @@ -11,7 +12,7 @@ using System.Threading.Tasks; namespace AbstractLawFirmFileImplement.Implements { - public class ComponentStorage + public class ComponentStorage: IComponentStorage { private readonly DataFileSingleton source; public ComponentStorage() diff --git a/LawFirm/LawFirmView/Program.cs b/LawFirm/LawFirmView/Program.cs index ab37d8c..cffdc50 100644 --- a/LawFirm/LawFirmView/Program.cs +++ b/LawFirm/LawFirmView/Program.cs @@ -1,7 +1,7 @@ using AbstractLawFirmBusinessLogic.BusinessLogic; using AbstractLawFirmContracts.BusinessLogicsContracts; using AbstractLawFirmContracts.StoragesContracts; -using AbstractLawFirmListImplement.Implements; +using AbstractLawFirmFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -- 2.25.1