From 8345b53f15ec9952354886fb06a4394d57067cd5 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 11 Feb 2023 17:28:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B=20?= =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?=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; + } + + } +}