From 792a5e999512b109135fd5eb9ee637cfcbb8ff32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 4 Mar 2023 12:58:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20Client=20ListImplement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ConfectionaryListImplement/Client.cs | 56 +++++++++++++ ConfectionaryListImplement/ClientStorage.cs | 79 +++++++++++++++++++ .../DataListSingleton.cs | 3 + 3 files changed, 138 insertions(+) create mode 100644 ConfectionaryListImplement/Client.cs create mode 100644 ConfectionaryListImplement/ClientStorage.cs diff --git a/ConfectionaryListImplement/Client.cs b/ConfectionaryListImplement/Client.cs new file mode 100644 index 0000000..a1f7048 --- /dev/null +++ b/ConfectionaryListImplement/Client.cs @@ -0,0 +1,56 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.ViewModels; +using ConfectioneryDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class Client : IClientModel + { + 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 int Id { get; private set; } + + 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, + }; + } +} diff --git a/ConfectionaryListImplement/ClientStorage.cs b/ConfectionaryListImplement/ClientStorage.cs new file mode 100644 index 0000000..d21fdbb --- /dev/null +++ b/ConfectionaryListImplement/ClientStorage.cs @@ -0,0 +1,79 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.SearchModels; +using ConfectioneryContracts.StoragesContract; +using ConfectioneryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConfectioneryListImplement +{ + public class ClientStorage : IClientStorage + { + private readonly DataListSingleton _source; + public ClientStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public ClientViewModel? Delete(ClientBindingModel model) + { + var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id); + if (res != null) + { + _source.Clients.Remove(res); + } + return res?.GetViewModel; + } + + public ClientViewModel? GetElement(ClientSearchModel model) + { + return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public List GetFilteredList(ClientSearchModel model) + { + if (model == null) + { + return new(); + } + if (model.Id.HasValue) + { + var res = GetElement(model); + return res != null ? new() { res } : new(); + } + if (model.Email != null) + { + return _source.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + return new(); + } + + public List GetFullList() + { + return _source.Clients.Select(x => x.GetViewModel).ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var res = Client.Create(model); + if (res != null) + { + _source.Clients.Add(res); + } + return res?.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + var res = _source.Clients.FirstOrDefault(x => x.Id == model.Id); + res?.Update(model); + return res?.GetViewModel; + } + } +} diff --git a/ConfectionaryListImplement/DataListSingleton.cs b/ConfectionaryListImplement/DataListSingleton.cs index 24ae616..93436e7 100644 --- a/ConfectionaryListImplement/DataListSingleton.cs +++ b/ConfectionaryListImplement/DataListSingleton.cs @@ -8,11 +8,14 @@ namespace ConfectioneryListImplement public List Components { get; set; } public List Orders { get; set; } public List Pastry { get; set; } + public List Clients { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Pastry = new List(); + Clients = new List(); } public static DataListSingleton GetInstance() {