diff --git a/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs new file mode 100644 index 0000000..929eb18 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopFileImplement/Models/Implementer.cs @@ -0,0 +1,8 @@ +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopFileImplement.Models +{ + public class Implementer : IImplementerModel + { + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs index 062f7e3..6625a94 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/DataListSingleton.cs @@ -9,13 +9,15 @@ namespace BlacksmithWorkshopListImplement public List Orders { get; set; } public List Manufactures { get; set; } public List Clients { get; set; } - private DataListSingleton() + public List Implementers { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Manufactures = new List(); Clients = new List(); - } + Implementers = new List(); + } public static DataListSingleton GetInstance() { if (_instance == null) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs new file mode 100644 index 0000000..261100d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/ImplementerStorage.cs @@ -0,0 +1,119 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.StoragesContracts; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopListImplement.Models; + +namespace BlacksmithWorkshopListImplement.Implements +{ + public class ImplementerStorage : IImplementerStorage + { + private readonly DataListSingleton _source; + public ImplementerStorage() + { + _source = DataListSingleton.GetInstance(); + } + 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; + } + public ImplementerViewModel? GetElement(ImplementerSearchModel model) + { + foreach (var implementer in _source.Implementers) + { + if (model.Id.HasValue && implementer.Id == model.Id) + { + return implementer.GetViewModel; + } + if (model.ImplementerFIO != null && model.Password != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO) && implementer.Password.Equals(model.Password)) + { + return implementer.GetViewModel; + } + if (model.ImplementerFIO != null && implementer.ImplementerFIO.Equals(model.ImplementerFIO)) + { + return implementer.GetViewModel; + } + } + return null; + } + public List GetFilteredList(ImplementerSearchModel model) + { + var result = new List(); + if (!model.Id.HasValue && string.IsNullOrEmpty(model.ImplementerFIO)) + { + return result; + } + if (model.Id.HasValue) + { + foreach (var implementer in _source.Implementers) + { + if (implementer.Id == model.Id) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + else + { + foreach (var implementer in _source.Implementers) + { + if (implementer.ImplementerFIO == model.ImplementerFIO) + { + result.Add(implementer.GetViewModel); + } + } + return result; + } + } + + 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; + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs index a84095f..162060f 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Implements/OrderStorage.cs @@ -79,7 +79,22 @@ namespace BlacksmithWorkshopListImplement.Implements } } } - return result; + else if (model.Status.HasValue)//далее ищем по статусу + { + foreach (var order in _source.Orders) + { + if (order.Status == model.Status) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + result.Add(vm); + } + } + } + return result; } public OrderViewModel? GetElement(OrderSearchModel model) { @@ -98,7 +113,34 @@ namespace BlacksmithWorkshopListImplement.Implements vm.ClientFIO = client?.ClientFIO ?? string.Empty; return vm; } - } + else if (model.ImplementerId.HasValue && order.ImplementerId == model.ImplementerId) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + else if (model.ImplementerId.HasValue && !model.Status.HasValue) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + else if (model.ImplementerId.HasValue && model.Status.HasValue) + { + OrderViewModel vm = order.GetViewModel; + var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId); + vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty; + var client = _source.Clients.Find(x => x.Id == order.ClientId); + vm.ClientFIO = client?.ClientFIO ?? string.Empty; + return vm; + } + } return null; } public OrderViewModel? Insert(OrderBindingModel model) diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs new file mode 100644 index 0000000..15a429a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Implementer.cs @@ -0,0 +1,48 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; + +namespace BlacksmithWorkshopListImplement.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, + }; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs index 4d95925..c183499 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshopListImplement/Models/Order.cs @@ -16,9 +16,8 @@ namespace BlacksmithWorkshopListImplement.Models public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime? DateImplement { get; private set; } public int ClientId { get; private set; } - //TODO - public int? ImplementerId => throw new NotImplementedException(); - public static Order? Create(OrderBindingModel? model) + public int? ImplementerId { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) { @@ -33,7 +32,8 @@ namespace BlacksmithWorkshopListImplement.Models Status = model.Status, DateCreate = model.DateCreate, DateImplement = model.DateImplement, - ClientId = model.ClientId + ClientId = model.ClientId, + ImplementerId = model.ImplementerId }; } public void Update(OrderBindingModel? model) @@ -43,6 +43,10 @@ namespace BlacksmithWorkshopListImplement.Models return; } Status = model.Status; + if (model.ImplementerId != null) + { + ImplementerId = model.ImplementerId; + } if (model.DateImplement != null) { DateImplement = model.DateImplement; @@ -57,6 +61,7 @@ namespace BlacksmithWorkshopListImplement.Models Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - }; + ImplementerFIO = DataListSingleton.GetInstance().Implementers.SingleOrDefault(x => x.Id == ImplementerId)?.ImplementerFIO ?? string.Empty + }; } } \ No newline at end of file