From 292fa41ba4d6bdf9e389b2b1a6138b12f97b0fcd Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 25 Mar 2023 15:48:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD=D0=B8=D0=BB=D0=B8?= =?UTF-8?q?=D1=89=D0=B0=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=20=D0=B2=20=D0=BF=D0=B0=D0=BC=D1=8F=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataListSingleton.cs | 2 + .../Implements/ClientStorage.cs | 105 ++++++++++++++++++ .../LawFirmListImplements/Models/Client.cs | 56 ++++++++++ 3 files changed, 163 insertions(+) create mode 100644 LawFirm/LawFirmListImplements/Implements/ClientStorage.cs create mode 100644 LawFirm/LawFirmListImplements/Models/Client.cs diff --git a/LawFirm/LawFirmListImplements/DataListSingleton.cs b/LawFirm/LawFirmListImplements/DataListSingleton.cs index dbbf993..6755587 100644 --- a/LawFirm/LawFirmListImplements/DataListSingleton.cs +++ b/LawFirm/LawFirmListImplements/DataListSingleton.cs @@ -14,11 +14,13 @@ namespace LawFirmListImplements public List Blanks { get; set; } public List Orders { get; set; } public List Documents { get; set; } + public List Clients { get; set; } private DataListSingleton() { Blanks = new List(); Orders = new List(); Documents = new List(); + Clients= new List(); } public static DataListSingleton GetInstance() { diff --git a/LawFirm/LawFirmListImplements/Implements/ClientStorage.cs b/LawFirm/LawFirmListImplements/Implements/ClientStorage.cs new file mode 100644 index 0000000..60a8ff6 --- /dev/null +++ b/LawFirm/LawFirmListImplements/Implements/ClientStorage.cs @@ -0,0 +1,105 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.SearchModels; +using LawFirmContracts.StorageContracts; +using LawFirmContracts.ViewModels; +using LawFirmListImplements.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawFirmListImplements.Implements +{ + public class ClientStorage : IClientStorage + { + private readonly DataListSingleton _source; + public ClientStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + foreach (var client in _source.Clients) + { + if ((!string.IsNullOrEmpty(model.Email) && client.Email == model.Email) || (model.Id.HasValue && client.Id == model.Id)) + { + return client.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(ClientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Email)) + { + return result; + } + var client = GetElement(model); + if (client != null) result.Add(client); + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var client in _source.Clients) + { + result.Add(client.GetViewModel); + } + return result; + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + model.Id = 1; + foreach (var client in _source.Clients) + { + if (model.Id <= client.Id) + { + model.Id = client.Id + 1; + } + } + var res = Client.Create(model); + if (res != null) + { + _source.Clients.Add(res); + } + return res?.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + foreach (var client in _source.Clients) + { + if (client.Id == model.Id) + { + client.Update(model); + return client.GetViewModel; + } + } + return null; + } + public ClientViewModel? Delete(ClientBindingModel model) + { + for (int i = 0; i < _source.Clients.Count; ++i) + { + if (_source.Clients[i].Id == model.Id) + { + var element = _source.Clients[i]; + _source.Clients.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + } +} diff --git a/LawFirm/LawFirmListImplements/Models/Client.cs b/LawFirm/LawFirmListImplements/Models/Client.cs new file mode 100644 index 0000000..012a620 --- /dev/null +++ b/LawFirm/LawFirmListImplements/Models/Client.cs @@ -0,0 +1,56 @@ +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; + +namespace LawFirmListImplements.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + + public string ClientFIO { get; private set; } = string.Empty; + + public string Email { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + ClientFIO = model.ClientFIO, + Email = model.Email, + Password = model.Password + }; + } + + public void Update(ClientBindingModel model) + { + if (model == null) + { + return; + } + ClientFIO = model.ClientFIO; + Email = model.Email; + Password = model.Password; + } + + public ClientViewModel GetViewModel => new() + { + Id = Id, + ClientFIO = ClientFIO, + Email = Email, + Password = Password, + }; + } +}