From ccfe49dde98d3914b9b28ae1ab4f3904b8ff0a4c Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Feb 2023 23:22:27 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs index 47b885b..bb10978 100644 --- a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -79,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - blank.Update(model); + source.Blanks.Remove(blank); source.SaveBlanks(); return blank.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 7629dfa..dd74260 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - document.Update(model); + source.Documents.Remove(document); source.SaveDocuments(); return document.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index baee8c5..46a8d01 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - order.Update(model); + source.Orders.Remove(order); source.SaveOrders(); return order.GetViewModel; } From 9c80b7fd37afd078a0959d1c17b63b9fc458247f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 15:30:32 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=BC=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 --- LawFirm/LawFirm.sln | 8 +- .../LawFirmFileImplement.csproj | 14 +++ LawFirm/LawFirmFileImplement/Models/Blank.cs | 74 ++++++++++++ .../LawFirmFileImplement/Models/Document.cs | 105 +++++++++++++++++ LawFirm/LawFirmFileImplement/Models/Order.cs | 110 ++++++++++++++++++ 5 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj create mode 100644 LawFirm/LawFirmFileImplement/Models/Blank.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Document.cs create mode 100644 LawFirm/LawFirmFileImplement/Models/Order.cs diff --git a/LawFirm/LawFirm.sln b/LawFirm/LawFirm.sln index 93a0ebb..362180a 100644 --- a/LawFirm/LawFirm.sln +++ b/LawFirm/LawFirm.sln @@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirm EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU {43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj new file mode 100644 index 0000000..7c491f4 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/LawFirm/LawFirmFileImplement/Models/Blank.cs b/LawFirm/LawFirmFileImplement/Models/Blank.cs new file mode 100644 index 0000000..2e7bbfd --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Blank.cs @@ -0,0 +1,74 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Blank : IBlankModel + { + public string BlankName { get; private set; } = String.Empty; + + public double Cost { get; set; } + + public int Id { get; private set; } + + public static Blank? Create(BlankBindingModel? model) + { + if (model == null) + { + return null; + } + return new Blank() + { + Id = model.Id, + BlankName = model.BlankName, + Cost = model.Cost + }; + } + + public static Blank? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Blank() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + BlankName = element.Element("BlankName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + + public void Update(BlankBindingModel? model) + { + if (model == null) + { + return; + } + BlankName = model.BlankName; + Cost = model.Cost; + } + public BlankViewModel GetViewModel => new() + { + Id = Id, + BlankName = BlankName, + Cost = Cost + }; + + public XElement GetXElement => new( + "Blank", + new XAttribute("Id", Id), + new XElement("BlankName", BlankName), + new XElement("Cost", Cost.ToString()) + ); + + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Document.cs b/LawFirm/LawFirmFileImplement/Models/Document.cs new file mode 100644 index 0000000..6484a59 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Document.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Document : IDocumentModel + { + public string DocumentName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public int Id { get; private set; } + + public Dictionary Blanks { get; private set; } = new(); + + private Dictionary? _documentBlanks = null; + public Dictionary DocumentBlanks + { + get + { + if (_documentBlanks == null) + { + var source = DataFileSingleton.GetInstance(); + _documentBlanks = Blanks.ToDictionary( + x => x.Key, + y => ((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!, y.Value) + ); + } + return _documentBlanks; + } + } + + + public static Document? Create(DocumentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Document() + { + Id = model.Id, + DocumentName = model.DocumentName, + Price = model.Price, + Blanks = model.DocumentBlanks.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("DocumentName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Blanks = element.Element("DocumentBlanks")!.Elements("DocumentBlank").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; + Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2); + _documentBlanks = null; + } + public DocumentViewModel GetViewModel => new() + { + Id = Id, + DocumentName = DocumentName, + Price = Price, + DocumentBlanks = DocumentBlanks + }; + + public XElement GetXElement => new( + "Document", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + new XElement("Price", Price.ToString()), + new XElement("DocumentBlanks", Blanks.Select(x => + new XElement("DocumentBlank", + new XElement("Key", x.Key), + new XElement("Value", x.Value))) + .ToArray())); + } +} diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs new file mode 100644 index 0000000..28a6a3a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -0,0 +1,110 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.ViewModels; +using LawFirmDataModels.Enums; +using LawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement.Models +{ + public class Order : IOrderModel + { + public int DocumentId { get; private set; } + + public string DocumentName { 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 + { + DocumentId = model.DocumentId, + DocumentName = model.DocumentName, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + Id = model.Id, + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + DocumentName = element.Element("DocumentName")!.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 = Convert.ToDateTime(element.Element("DateCreate")!.Value) + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + DocumentId = model.DocumentId; + DocumentName = model.DocumentName; + Count = model.Count; + Sum = model.Sum; + Status = model.Status; + DateCreate = model.DateCreate; + DateImplement = model.DateImplement; + Id = model.Id; + } + + public OrderViewModel GetViewModel => new() + { + DocumentId = DocumentId, + DocumentName = DocumentName, + Count = Count, + Sum = Sum, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + Status = Status, + }; + + public XElement GetXElement => new( + "Order", + new XAttribute("Id", Id), + new XElement("DocumentName", DocumentName), + 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()) + ); + } +} From e390ece7b691edd38f7d4ffc41915de3eefdd1ea Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 16:28:53 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D1=81=D0=B8=D0=BD=D0=B3=D0=BB=D1=82=D0=BE=D0=BD=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LawFirmFileImplement/DataFileSingleton.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/DataFileSingleton.cs diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..baa110a --- /dev/null +++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs @@ -0,0 +1,55 @@ +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace LawFirmFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string BlankFileName = "Blank.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string DocumentFileName = "Document.xml"; + public List Blanks { 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 SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement); + public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!; + Documents = LoadData(DocumentFileName, "Document", x => Document.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); + } + } + } +} From 75a544e690e59722bbcff0e14fecf559208bdcb0 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:28:24 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B?= =?UTF-8?q?=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= =?UTF-8?q?=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8=D1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/BlankStorage.cs | 88 +++++++++++++++++++ .../Implements/DocumentStorage.cs | 87 ++++++++++++++++++ .../Implements/OrderStorage.cs | 87 ++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs create mode 100644 LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs new file mode 100644 index 0000000..47b885b --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -0,0 +1,88 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + public class BlankStorage : IBlankStorage + { + private readonly DataFileSingleton source; + + public BlankStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public BlankViewModel? GetElement(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue) + { + return null; + } + return source.Blanks + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(BlankSearchModel model) + { + if (string.IsNullOrEmpty(model.BlankName)) + { + return new(); + } + return source.Blanks + .Where(x => x.BlankName.Contains(model.BlankName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Blanks.Select(x => x.GetViewModel).ToList(); + } + + public BlankViewModel? Insert(BlankBindingModel model) + { + model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1; + var newBlank = Blank.Create(model); + if (newBlank == null) + { + return null; + } + source.Blanks.Add(newBlank); + source.SaveBlanks(); + return newBlank.GetViewModel; + } + + public BlankViewModel? Update(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + public BlankViewModel? Delete(BlankBindingModel model) + { + var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id); + if (blank == null) + { + return null; + } + blank.Update(model); + source.SaveBlanks(); + return blank.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs new file mode 100644 index 0000000..8de8fd2 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal 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; + } + document.Update(model); + source.SaveDocuments(); + return document.GetViewModel; + } + + } +} diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..7b35304 --- /dev/null +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,87 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmFileImplement.Implements +{ + internal class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + 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 List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => x.GetViewModel).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 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 order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return order.GetViewModel; + } + + } +} From daf95e27b6bce80312797a7e8925326b50201a61 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:41:53 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=92=D1=80=D0=BE=D0=B4=D0=B5=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirm/LawFirmView.csproj | 1 + LawFirm/LawFirm/Program.cs | 4 +++- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj | 2 +- 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/LawFirm/LawFirm/LawFirmView.csproj b/LawFirm/LawFirm/LawFirmView.csproj index 45754fd..7f7c8cf 100644 --- a/LawFirm/LawFirm/LawFirmView.csproj +++ b/LawFirm/LawFirm/LawFirmView.csproj @@ -17,6 +17,7 @@ + diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index b634a21..09dd87f 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -1,7 +1,7 @@ using LawFirmBusinessLogic.BusinessLogics; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StorageContracts; -using LawFirmListImplements.Implements; +using LawFirmFileImplement.Implements; using LawFirmView; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -41,9 +41,11 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 8de8fd2..7629dfa 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class DocumentStorage : IDocumentStorage + public class DocumentStorage : IDocumentStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 7b35304..baee8c5 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace LawFirmFileImplement.Implements { - internal class OrderStorage : IOrderStorage + public class OrderStorage : IOrderStorage { private readonly DataFileSingleton source; diff --git a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj index 7c491f4..77fe5b1 100644 --- a/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj +++ b/LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj @@ -1,4 +1,4 @@ - + net6.0 From 862baf93b68b90a828dc40f5d01abd3675407e26 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 13 Feb 2023 09:29:17 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=B0=20=D0=BB?= =?UTF-8?q?=D0=B0=D0=B1=202=20=D0=B1=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Models/Order.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 28a6a3a..7672d1a 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -63,7 +63,7 @@ namespace LawFirmFileImplement.Models 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 = Convert.ToDateTime(element.Element("DateCreate")!.Value) + DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value) }; } From b2c61a619a9f9706b4bebb43ff26f982eb812aa2 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 26 Feb 2023 23:22:27 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D1=83=D0=B4?= =?UTF-8?q?=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs | 2 +- LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs index 47b885b..bb10978 100644 --- a/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs @@ -79,7 +79,7 @@ namespace LawFirmFileImplement.Implements { return null; } - blank.Update(model); + source.Blanks.Remove(blank); source.SaveBlanks(); return blank.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs index 7629dfa..dd74260 100644 --- a/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - document.Update(model); + source.Documents.Remove(document); source.SaveDocuments(); return document.GetViewModel; } diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index baee8c5..46a8d01 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -78,7 +78,7 @@ namespace LawFirmFileImplement.Implements { return null; } - order.Update(model); + source.Orders.Remove(order); source.SaveOrders(); return order.GetViewModel; } From 8507a11132518a7e9b441da1b689bf95c37b793f Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 10 Mar 2023 19:37:13 +0400 Subject: [PATCH 8/8] =?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=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/OrderStorage.cs | 28 ++++++++++++++----- LawFirm/LawFirmFileImplement/Models/Order.cs | 12 -------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs index 46a8d01..3220716 100644 --- a/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs @@ -26,8 +26,8 @@ namespace LawFirmFileImplement.Implements { return null; } - return source.Orders - .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return GetViewModel(source.Orders + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))); } public List GetFilteredList(OrderSearchModel model) @@ -38,13 +38,13 @@ namespace LawFirmFileImplement.Implements } return source.Orders .Where(x => x.Id == model.Id) - .Select(x => x.GetViewModel) + .Select(x => GetViewModel(x)) .ToList(); } public List GetFullList() { - return source.Orders.Select(x => x.GetViewModel).ToList(); + return source.Orders.Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -57,7 +57,7 @@ namespace LawFirmFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return newOrder.GetViewModel; + return GetViewModel(newOrder); } public OrderViewModel? Update(OrderBindingModel model) @@ -69,7 +69,7 @@ namespace LawFirmFileImplement.Implements } order.Update(model); source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); } public OrderViewModel? Delete(OrderBindingModel model) { @@ -80,7 +80,21 @@ namespace LawFirmFileImplement.Implements } source.Orders.Remove(order); source.SaveOrders(); - return order.GetViewModel; + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var document in source.Documents) + { + if (document.Id == order.DocumentId) + { + viewModel.DocumentName = document.DocumentName; + break; + } + } + return viewModel; } } diff --git a/LawFirm/LawFirmFileImplement/Models/Order.cs b/LawFirm/LawFirmFileImplement/Models/Order.cs index 7672d1a..31bb7e8 100644 --- a/LawFirm/LawFirmFileImplement/Models/Order.cs +++ b/LawFirm/LawFirmFileImplement/Models/Order.cs @@ -15,8 +15,6 @@ namespace LawFirmFileImplement.Models { public int DocumentId { get; private set; } - public string DocumentName { get; private set; } = string.Empty; - public int Count { get; private set; } public double Sum { get; private set; } @@ -38,7 +36,6 @@ namespace LawFirmFileImplement.Models return new Order { DocumentId = model.DocumentId, - DocumentName = model.DocumentName, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -57,7 +54,6 @@ namespace LawFirmFileImplement.Models return new Order() { Id = Convert.ToInt32(element.Attribute("Id")!.Value), - DocumentName = element.Element("DocumentName")!.Value, DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value), @@ -73,20 +69,13 @@ namespace LawFirmFileImplement.Models { return; } - DocumentId = model.DocumentId; - DocumentName = model.DocumentName; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; - Id = model.Id; } public OrderViewModel GetViewModel => new() { DocumentId = DocumentId, - DocumentName = DocumentName, Count = Count, Sum = Sum, DateCreate = DateCreate, @@ -98,7 +87,6 @@ namespace LawFirmFileImplement.Models public XElement GetXElement => new( "Order", new XAttribute("Id", Id), - new XElement("DocumentName", DocumentName), new XElement("DocumentId", DocumentId.ToString()), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()),