diff --git a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs index ca1efab..37fe1ac 100644 --- a/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs +++ b/LawFirm/AbstractLawFirmListImplement/DataListSingleton.cs @@ -13,11 +13,13 @@ namespace AbstractLawFirmListImplement public List Components { get; set; } public List Orders { get; set; } public List Documents { get; set; } + public List Implementers { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); Documents = new List(); + Implementers = new List(); } public static DataListSingleton GetInstance() { diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/ImplementerStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..b90cb3a --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,111 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.SearchModels; +using AbstractLawFirmContracts.StoragesContracts; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var x in _source.Implementers) + { + if (model.Id.HasValue && x.Id == model.Id) + return x.GetViewModel; + if (model.ImplementerFIO != null && model.Password != null && + x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password)) + return x.GetViewModel; + if (model.ImplementerFIO != null && x.ImplementerFIO.Equals(model.ImplementerFIO)) + return x.GetViewModel; + } + return null; + } + + public List GetFilteredList(ImplementerSearchModel model) + { + if (model == null) + { + return new(); + } + List list = new(); + if (model.ImplementerFIO != null) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO.Contains(model.ImplementerFIO)) + { + list.Add(implementer.GetViewModel); + } + } + } + return list; + } + + public List GetFullList() + { + var result = new List(); + foreach (var implementer in _source.Implementers) + { + result.Add(implementer.GetViewModel); + } + return result; + } + + 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 res = Implementer.Create(model); + if (res != null) + { + _source.Implementers.Add(res); + } + return res?.GetViewModel; + } + + public ImplementerViewModel? Update(ImplementerBindingModel model) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.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; + } + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs b/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs index 6d5d65c..661f622 100644 --- a/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs +++ b/LawFirm/AbstractLawFirmListImplement/Implements/OrderStorage.cs @@ -31,15 +31,44 @@ namespace AbstractLawFirmListImplement.Implements model) { var result = new List(); - if (!model.Id.HasValue) + if (model.DateFrom.HasValue && model.DateTo.HasValue) { - return result; - } - foreach (var order in _source.Orders) - { - if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + foreach (var order in _source.Orders) { - result.Add(AccessDocumentStorage(order.GetViewModel)); + if (order.Id == model.Id || model.DateFrom <= order.DateCreate && order.DateCreate <= model.DateTo) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.ClientId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ClientId == model.ClientId) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.ImplementerId.HasValue) + { + foreach (var order in _source.Orders) + { + if (order.ImplementerId == model.ImplementerId) + { + result.Add(GetViewModel(order)); + } + } + } + if (model.Status != null) + { + foreach (var order in _source.Orders) + { + if (model.Status.Equals(order.Status)) + { + result.Add(GetViewModel(order)); + } } } return result; @@ -102,6 +131,19 @@ namespace AbstractLawFirmListImplement.Implements } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var document in _source.Documents) + { + if (document.Id == order.DocumentId) + { + viewModel.DocumentName = document.DocumentName; + break; + } + } + return viewModel; + } public OrderViewModel AccessDocumentStorage(OrderViewModel model) { foreach (var document in _source.Documents) diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Implementer.cs b/LawFirm/AbstractLawFirmListImplement/Models/Implementer.cs new file mode 100644 index 0000000..f947194 --- /dev/null +++ b/LawFirm/AbstractLawFirmListImplement/Models/Implementer.cs @@ -0,0 +1,60 @@ +using AbstractLawFirmContracts.BindingModels; +using AbstractLawFirmContracts.ViewModels; +using AbstractLawFirmDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AbstractLawFirmListImplement.Models +{ + public class Implementer : IImplementerModel + { + public int Id { get; private set; } + + public string ImplementerFIO { get; private set; } = string.Empty; + + public string Password { get; private set; } = string.Empty; + + public int WorkExperience { get; private set; } + + public int Qualification { get; private set; } + + public static Implementer? Create(ImplementerBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + Id = model.Id, + Password = model.Password, + Qualification = model.Qualification, + ImplementerFIO = model.ImplementerFIO, + WorkExperience = model.WorkExperience, + }; + } + + public void Update(ImplementerBindingModel model) + { + if (model == null) + { + return; + } + Password = model.Password; + Qualification = model.Qualification; + ImplementerFIO = model.ImplementerFIO; + WorkExperience = model.WorkExperience; + } + + public ImplementerViewModel GetViewModel => new() + { + Id = Id, + Password = Password, + Qualification = Qualification, + ImplementerFIO = ImplementerFIO, + }; + } +} diff --git a/LawFirm/AbstractLawFirmListImplement/Models/Order.cs b/LawFirm/AbstractLawFirmListImplement/Models/Order.cs index 368d1ed..9d5fc89 100644 --- a/LawFirm/AbstractLawFirmListImplement/Models/Order.cs +++ b/LawFirm/AbstractLawFirmListImplement/Models/Order.cs @@ -15,6 +15,7 @@ namespace AbstractLawFirmListImplement.Models public int Id { get; private set; } public int DocumentId { get; private set; } public int ClientId { get; private set; } + public int? ImplementerId { get; private set; } public int Count { get; private set; } public double Sum { get; private set; } public OrderStatus Status { get; private set; } @@ -30,6 +31,8 @@ namespace AbstractLawFirmListImplement.Models { Id = model.Id, DocumentId = model.DocumentId, + ClientId = model.ClientId, + ImplementerId = model.ImplementerId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -45,6 +48,8 @@ namespace AbstractLawFirmListImplement.Models } Id = model.Id; DocumentId = model.DocumentId; + ClientId = model.ClientId; + ImplementerId = model.ImplementerId; Count = model.Count; Sum = model.Sum; Status = model.Status; @@ -55,6 +60,9 @@ namespace AbstractLawFirmListImplement.Models { Id = Id, DocumentId = DocumentId, + ClientId = ClientId, + ImplementerId = ImplementerId, + ImplementerFIO = DataListSingleton.GetInstance().Implementers.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty, Count = Count, Sum = Sum, Status = Status,