From e1bbc9ba930b8367c5a8a0e6b198237b4da638c6 Mon Sep 17 00:00:00 2001 From: kamilia Date: Mon, 6 May 2024 00:29:13 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BA=D0=BE=D0=BB=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BB=D0=B0,=20=D0=BD=D0=B0=D0=B4=D0=B5=D1=8E?= =?UTF-8?q?=D1=81=D1=8C=20=D0=B1=D0=B5=D0=B7=20=D0=BA=D0=BE=D0=BD=D1=84?= =?UTF-8?q?=D0=BB=D0=B8=D0=BA=D1=82=D0=BE=D0=B2=20=D0=BE=D0=B1=D0=BE=D0=B9?= =?UTF-8?q?=D0=B4=D1=83=D1=81=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractShopListImplement/Client.cs | 52 ++++++++ .../ClientStorage.cs | 112 ++++++++++++++++++ .../DataListSingleton.cs | 6 + .../AbstractShopListImplement/Order.cs | 8 ++ .../AbstractShopListImplement/OrderStorage.cs | 19 ++- .../AircraftPlantFileImplement/Order.cs | 6 +- .../OrderStorage.cs | 12 +- 7 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 AircraftPlant/AbstractShopListImplement/Client.cs create mode 100644 AircraftPlant/AbstractShopListImplement/ClientStorage.cs diff --git a/AircraftPlant/AbstractShopListImplement/Client.cs b/AircraftPlant/AbstractShopListImplement/Client.cs new file mode 100644 index 0000000..4969f1e --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/Client.cs @@ -0,0 +1,52 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.ViewModels; +using AircraftPlantDataModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement +{ + public class Client : IClientModel + { + public int Id { get; private set; } + public string ClientFIO { get; 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/AircraftPlant/AbstractShopListImplement/ClientStorage.cs b/AircraftPlant/AbstractShopListImplement/ClientStorage.cs new file mode 100644 index 0000000..1b1a9b0 --- /dev/null +++ b/AircraftPlant/AbstractShopListImplement/ClientStorage.cs @@ -0,0 +1,112 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.SearchModels; +using AircraftPlantContracts.StoragesContracts; +using AircraftPlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftPlantListImplement +{ + public class ClientStorage : IClientStorage + { + 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.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue) + { + return null; + } + + foreach (var client in _source.Clients) + { + if (model.Id.HasValue && model.Id == client.Id) + return client.GetViewModel; + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && + client.Email.Equals(model.Email) && client.Password.Equals(model.Password)) + return client.GetViewModel; + if (!string.IsNullOrEmpty(model.Email) && client.Email.Equals(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/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs index 7754b68..11b1cc2 100644 --- a/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs +++ b/AircraftPlant/AbstractShopListImplement/DataListSingleton.cs @@ -32,6 +32,11 @@ namespace AircraftPlantListImplement /// public List Planes { get; set; } + /// + /// Список классов-моделей клиентов + /// + public List Clients { get; set; } + /// /// Конструктор /// @@ -40,6 +45,7 @@ namespace AircraftPlantListImplement Components = new List(); Orders = new List(); Planes = new List(); + Clients = new List(); } /// /// Получить ссылку на класс diff --git a/AircraftPlant/AbstractShopListImplement/Order.cs b/AircraftPlant/AbstractShopListImplement/Order.cs index e4778ca..3b407d4 100644 --- a/AircraftPlant/AbstractShopListImplement/Order.cs +++ b/AircraftPlant/AbstractShopListImplement/Order.cs @@ -5,6 +5,7 @@ using AircraftPlantDataModels.Models; using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; @@ -25,6 +26,11 @@ namespace AircraftPlantListImplement.Models /// public int PlaneId { get; private set; } + /// + /// Идентификатор клиента + /// + public int ClientId { get; private set; } + /// /// Количество изделий /// @@ -66,6 +72,7 @@ namespace AircraftPlantListImplement.Models { Id = model.Id, PlaneId = model.PlaneId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -94,6 +101,7 @@ namespace AircraftPlantListImplement.Models { Id = Id, PlaneId = PlaneId, + ClientId = model.ClientId, Count = Count, Sum = Sum, Status = Status, diff --git a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs index 293d7a0..582dba3 100644 --- a/AircraftPlant/AbstractShopListImplement/OrderStorage.cs +++ b/AircraftPlant/AbstractShopListImplement/OrderStorage.cs @@ -49,7 +49,7 @@ namespace AircraftPlantListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue) + if (!model.Id.HasValue || !model.DateFrom.HasValue || !model.DateTo.HasValue || !model.ClientId.HasValue) { return result; } @@ -66,6 +66,13 @@ namespace AircraftPlantListImplement.Implements return result; } + if (model.ClientId.HasValue && !model.Id.HasValue) + { + foreach (var order in _source.Orders) + { + result.Add(GetViewModel(order)); + } + } foreach (var order in _source.Orders) { @@ -173,6 +180,16 @@ namespace AircraftPlantListImplement.Implements break; } } + + foreach (var client in _source.Clients) + { + if (client.Id == order.ClientId) + { + viewModel.ClientFIO = client.ClientFIO; + break; + } + } + return viewModel; } } diff --git a/AircraftPlant/AircraftPlantFileImplement/Order.cs b/AircraftPlant/AircraftPlantFileImplement/Order.cs index bc338d7..4be03f1 100644 --- a/AircraftPlant/AircraftPlantFileImplement/Order.cs +++ b/AircraftPlant/AircraftPlantFileImplement/Order.cs @@ -15,7 +15,7 @@ namespace AircraftPlantFileImplement.Models { public int Id { get; private set; } public int PlaneId { 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; } @@ -31,6 +31,7 @@ namespace AircraftPlantFileImplement.Models { Id = model.Id, PlaneId = model.PlaneId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -48,6 +49,7 @@ namespace AircraftPlantFileImplement.Models { Id = Convert.ToInt32(element.Attribute("Id")!.Value), PlaneId = Convert.ToInt32(element.Element("PlaneId")!.Value), + ClientId = Convert.ToInt32(element.Element("ClientId")!.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), @@ -69,6 +71,7 @@ namespace AircraftPlantFileImplement.Models { Id = Id, PlaneId = PlaneId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, @@ -78,6 +81,7 @@ namespace AircraftPlantFileImplement.Models public XElement GetXElement => new("Order", new XAttribute("Id", Id), new XElement("PlaneId", PlaneId), + new XElement("ClientId", ClientId), new XElement("Count", Count.ToString()), new XElement("Sum", Sum.ToString()), new XElement("Status", Status.ToString()), diff --git a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs index 2a308bd..28fd55a 100644 --- a/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs +++ b/AircraftPlant/AircraftPlantFileImplement/OrderStorage.cs @@ -37,6 +37,14 @@ namespace AircraftPlantFileImplement.Implements .ToList(); } + if (model.ClientId.HasValue && !model.Id.HasValue) + { + return _source.Orders + .Where(x => x.ClientId == model.ClientId) + .Select(x => x.GetViewModel) + .ToList(); + } + return _source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList(); } public OrderViewModel? GetElement(OrderSearchModel model) @@ -86,7 +94,9 @@ namespace AircraftPlantFileImplement.Implements { var viewModel = order.GetViewModel; var plane = _source.Planes.FirstOrDefault(x => x.Id == order.PlaneId); - viewModel.PlaneName = plane?.PlaneName; + viewModel.PlaneName = plane?.PlaneName ?? string.Empty; + var client = _source.Clients.FirstOrDefault(x => x.Id == order.ClientId); + viewModel.ClientFIO = client?.ClientFIO ?? string.Empty; return viewModel; } }