From 226908644be2771ccdb8ded0478883726bb56d54 Mon Sep 17 00:00:00 2001 From: Ivan_Starostin Date: Sun, 2 Jun 2024 18:27:38 +0400 Subject: [PATCH] Upload files to 'ShipyardListImplement' --- ShipyardListImplement/DataListSingleton.cs | 2 + ShipyardListImplement/Implementer.cs | 54 +++++++++++ ShipyardListImplement/ImplementerStorage.cs | 102 ++++++++++++++++++++ ShipyardListImplement/Order.cs | 7 +- ShipyardListImplement/OrderStorage.cs | 26 ++--- 5 files changed, 177 insertions(+), 14 deletions(-) create mode 100644 ShipyardListImplement/Implementer.cs create mode 100644 ShipyardListImplement/ImplementerStorage.cs diff --git a/ShipyardListImplement/DataListSingleton.cs b/ShipyardListImplement/DataListSingleton.cs index 121e9ea..ddb5282 100644 --- a/ShipyardListImplement/DataListSingleton.cs +++ b/ShipyardListImplement/DataListSingleton.cs @@ -9,12 +9,14 @@ namespace ShipyardListImplement public List Orders { get; set; } public List Ships { get; set; } public List Clients { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Ships = new List(); Clients = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/ShipyardListImplement/Implementer.cs b/ShipyardListImplement/Implementer.cs new file mode 100644 index 0000000..962a853 --- /dev/null +++ b/ShipyardListImplement/Implementer.cs @@ -0,0 +1,54 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.ViewModels; +using ShipyardDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + public string ImplementerFIO { get; private set; } = string.Empty; + public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } = 0; + public int Qualification { get; set; } = 0; + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new Implementer() + { + Id = model.Id, + ImplementerFIO = model.ImplementerFIO, + Password = model.Password, + WorkExperience = model.WorkExperience, + Qualification = model.Qualification + }; + } + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + ImplementerFIO = model.ImplementerFIO; + Password = model.Password; + WorkExperience = model.WorkExperience; + Qualification = model.Qualification; + } + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + ImplementerFIO = ImplementerFIO, + Password = Password, + WorkExperience = WorkExperience, + Qualification = Qualification + }; + } +} diff --git a/ShipyardListImplement/ImplementerStorage.cs b/ShipyardListImplement/ImplementerStorage.cs new file mode 100644 index 0000000..a7de20e --- /dev/null +++ b/ShipyardListImplement/ImplementerStorage.cs @@ -0,0 +1,102 @@ +using ShipyardContracts.BindingModels; +using ShipyardContracts.SearchModels; +using ShipyardContracts.StorageContracts; +using ShipyardContracts.ViewModels; +using ShipyardListImplement; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ShipyardListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ImplementerFIO) && string.IsNullOrEmpty(model.Password)) + { + return result; + } + foreach (var implementer in _source.Implementers) + { + if (model.ImplementerFIO != null && implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var implementer in _source.Implementers) + { + if ((string.IsNullOrEmpty(model.ImplementerFIO) || implementer.ImplementerFIO == model.ImplementerFIO) && + (!model.Id.HasValue || implementer.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || implementer.Password == model.Password)) + { + return implementer.GetViewModel; + } + } + return null; + } + public ImplementerViewModel? Insert(ImplementerBindingModel model) + { + model.Id = 1; + foreach (var implementer in _source.Implementers) + { + if (model.Id <= implementer.Id) + { + model.Id = implementer.Id + 1; + } + } + var newImplementer = Implementer.Create(model); + if (newImplementer == null) + { + return null; + } + _source.Implementers.Add(newImplementer); + return newImplementer.GetViewModel; + } + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (model.Id == implementer.Id) + { + implementer.Update(model); + return implementer.GetViewModel; + } + } + return null; + } + public ImplementerViewModel? Delete(ImplementerBindingModel model) + { + for (int i = 0; i < _source.Implementers.Count; ++i) + { + if (_source.Implementers[i].Id == model.Id) + { + var element = _source.Implementers[i]; + _source.Implementers.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} \ No newline at end of file diff --git a/ShipyardListImplement/Order.cs b/ShipyardListImplement/Order.cs index 6f07fb2..b6e723b 100644 --- a/ShipyardListImplement/Order.cs +++ b/ShipyardListImplement/Order.cs @@ -2,6 +2,7 @@ using ShipyardContracts.ViewModels; using ShipyardDataModels.Enums; using ShipyardDataModels.Models; +using System.Reflection; namespace ShipyardListImplement { @@ -15,6 +16,7 @@ namespace ShipyardListImplement public DateTime DateCreate { get; private set; } public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public static Order? Create(OrderBindingModel? model) { @@ -32,6 +34,7 @@ namespace ShipyardListImplement DateCreate = model.DateCreate, DateImplement = model.DateImplement, ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -42,7 +45,8 @@ namespace ShipyardListImplement } Status = model.Status; DateImplement = model.DateImplement; - } + ImplementerId = model.ImplementerId; + } public OrderViewModel GetViewModel => new() { Id = Id, @@ -53,6 +57,7 @@ namespace ShipyardListImplement DateCreate = DateCreate, DateImplement = DateImplement, ClientId = ClientId, + ImplementerId = ImplementerId }; } } diff --git a/ShipyardListImplement/OrderStorage.cs b/ShipyardListImplement/OrderStorage.cs index 8e4ccfe..3a4e76e 100644 --- a/ShipyardListImplement/OrderStorage.cs +++ b/ShipyardListImplement/OrderStorage.cs @@ -45,8 +45,10 @@ namespace ShipyardListImplement } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) - { + if ((model.Id.HasValue && order.Id == model.Id) || + (model.ImplementerId.HasValue && model.Status.HasValue && + order.ImplementerId == model.ImplementerId && order.Status == model.Status)) + { return order.GetViewModel; } } @@ -97,20 +99,18 @@ namespace ShipyardListImplement } public OrderViewModel AccessShipStorage(OrderViewModel model) { + if (model == null) + return null; var client = _source.Clients.FirstOrDefault(x => x.Id == model.ClientId); if (client != null) - { model.ClientFIO = client.ClientFIO; - } - foreach (var Ship in _source.Ships) - { - if (Ship.Id == model.Id) - { - model.ShipName = Ship.ShipName; - break; - } - } - return model; + var ship = _source.Ships.FirstOrDefault(x => x.Id == model.Id); + if (ship != null) + model.ShipName = ship.ShipName; + var implementer = _source.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId); + if (implementer != null) + model.ImplementerFIO = implementer.ImplementerFIO; + return model; } } }