From f90a4c6e3015950d082c4c9a8bc946cd704d4fa8 Mon Sep 17 00:00:00 2001 From: ekallin Date: Sat, 6 Apr 2024 14:54:44 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BE=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B9=20=D0=BF=D0=B0=D0=BC?= =?UTF-8?q?=D1=8F=D1=82=D0=B8=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D1=8B=20=D1=81=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SushiBarListImplements/DataListSingleton.cs | 2 + .../Implements/ClientStorage.cs | 106 ++++++++++++++++++ SushiBarListImplements/Models/Client.cs | 45 ++++++++ SushiBarListImplements/Models/Order.cs | 8 +- 4 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 SushiBarListImplements/Implements/ClientStorage.cs create mode 100644 SushiBarListImplements/Models/Client.cs diff --git a/SushiBarListImplements/DataListSingleton.cs b/SushiBarListImplements/DataListSingleton.cs index 309dfcd..7074ae2 100644 --- a/SushiBarListImplements/DataListSingleton.cs +++ b/SushiBarListImplements/DataListSingleton.cs @@ -8,11 +8,13 @@ namespace SushiBarListImplement public List Components { get; set; } public List Orders { get; set; } public List Sushis { get; set; } + public List Clients { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Sushis = new List(); + Clients = new List(); } public static DataListSingleton GetInstance() { diff --git a/SushiBarListImplements/Implements/ClientStorage.cs b/SushiBarListImplements/Implements/ClientStorage.cs new file mode 100644 index 0000000..22ea4d9 --- /dev/null +++ b/SushiBarListImplements/Implements/ClientStorage.cs @@ -0,0 +1,106 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.SearchModel; +using SushiBarContracts.ViewModels; +using SushiBarListImplement; +using SushiBarListImplements.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SushiBarListImplements.Implements +{ + public class ClientStorage + { + private readonly DataListSingleton _source; + public ClientStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var client in _source.Clients) + { + result.Add(client.GetViewModel); + } + return result; + } + public List GetFilteredList(ClientSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.Email)) + { + return result; + } + foreach (var client in _source.Clients) + { + if (client.Email.Contains(model.Email)) + { + result.Add(client.GetViewModel); + } + } + return result; + } + 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.Email == model.Email) + { + return client.GetViewModel; + } + } + return null; + } + 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 newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + _source.Clients.Add(newClient); + return newClient.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/SushiBarListImplements/Models/Client.cs b/SushiBarListImplements/Models/Client.cs new file mode 100644 index 0000000..19359c7 --- /dev/null +++ b/SushiBarListImplements/Models/Client.cs @@ -0,0 +1,45 @@ +using SushiBarContracts.BindingModel; +using SushiBarContracts.ViewModels; +using SushiBarDataModels; + +namespace SushiBarListImplements.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + public string ClientFIO { get; private set; } = string.Empty; + public string Email { get; set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public static Client? Create(ClientBindingModel? model) + { + if (model == null) + { + return null; + } + return new Client() + { + 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/SushiBarListImplements/Models/Order.cs b/SushiBarListImplements/Models/Order.cs index a0a3e5a..b346a95 100644 --- a/SushiBarListImplements/Models/Order.cs +++ b/SushiBarListImplements/Models/Order.cs @@ -10,6 +10,7 @@ namespace SushiBarListImplements.Models { public int Id { get; private set; } public int SushiId { get; private set; } + public int ClientId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -30,7 +31,8 @@ namespace SushiBarListImplements.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement + DateImplement = model.DateImplement, + ClientId = model.ClientId, }; } @@ -46,6 +48,7 @@ namespace SushiBarListImplements.Models Status = model.Status; DateCreate = model.DateCreate; DateImplement = model.DateImplement; + ClientId = model.ClientId; } public OrderViewModel GetViewModel => new() @@ -56,7 +59,8 @@ namespace SushiBarListImplements.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement + DateImplement = DateImplement, + ClientId = ClientId, }; } }