From 58d7425a2e5dac58f9c20cd53038e38912296b53 Mon Sep 17 00:00:00 2001 From: Efi Date: Wed, 14 Feb 2024 17:20:07 +0400 Subject: [PATCH] Add: MotorPlantBusinessLogics and MotorPlantListImplement Rename: Product to Engine --- MotorPlant/MotorPlant.sln | 15 ++- .../BusinessLogics/ComponentLogic.cs | 120 ++++++++++++++++++ .../BusinessLogics/EngineLogic.cs | 40 ++++++ .../BusinessLogics/OrderLogic.cs | 40 ++++++ .../MotorPlantBusinessLogics.csproj | 13 ++ ...tBindingModel.cs => EngineBindingModel.cs} | 6 +- .../BindingModels/OrderBindingModel.cs | 2 +- .../{IProductLogic.cs => IEngineLogic.cs} | 12 +- .../MotorPlantContracts.csproj | 4 + ...uctSearchModel.cs => EngineSearchModel.cs} | 4 +- .../StoragesContracts/IEngineStorage.cs | 26 ++++ .../StoragesContracts/IProductStorage.cs | 26 ---- ...ProductViewModel.cs => EngineViewModel.cs} | 6 +- .../ViewModels/OrderViewModel.cs | 4 +- .../{IProductModel.cs => IEngineModel.cs} | 6 +- .../Models/IOrderModel.cs | 2 +- .../Implements/ComponentStorage.cs | 114 +++++++++++++++++ .../Implements/EngineStorage.cs | 40 ++++++ .../Implements/OrderStorage.cs | 45 +++++++ .../Models/Component.cs | 51 ++++++++ .../MotorPlantListImplement/Models/Engine.cs | 57 +++++++++ .../MotorPlantListImplement/Models/Order.cs | 43 +++++++ .../MotorPlantListImplement.csproj | 14 ++ 23 files changed, 640 insertions(+), 50 deletions(-) create mode 100644 MotorPlant/MotorPlantBusinessLogics/BusinessLogics/ComponentLogic.cs create mode 100644 MotorPlant/MotorPlantBusinessLogics/BusinessLogics/EngineLogic.cs create mode 100644 MotorPlant/MotorPlantBusinessLogics/BusinessLogics/OrderLogic.cs create mode 100644 MotorPlant/MotorPlantBusinessLogics/MotorPlantBusinessLogics.csproj rename MotorPlant/MotorPlantContracts/BindingModels/{ProductBindingModel.cs => EngineBindingModel.cs} (58%) rename MotorPlant/MotorPlantContracts/BusinessLogicsContracts/{IProductLogic.cs => IEngineLogic.cs} (50%) rename MotorPlant/MotorPlantContracts/SearchModels/{ProductSearchModel.cs => EngineSearchModel.cs} (71%) create mode 100644 MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs delete mode 100644 MotorPlant/MotorPlantContracts/StoragesContracts/IProductStorage.cs rename MotorPlant/MotorPlantContracts/ViewModels/{ProductViewModel.cs => EngineViewModel.cs} (66%) rename MotorPlant/MotorPlantDataModels/Models/{IProductModel.cs => IEngineModel.cs} (57%) create mode 100644 MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs create mode 100644 MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs create mode 100644 MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs create mode 100644 MotorPlant/MotorPlantListImplement/Models/Component.cs create mode 100644 MotorPlant/MotorPlantListImplement/Models/Engine.cs create mode 100644 MotorPlant/MotorPlantListImplement/Models/Order.cs create mode 100644 MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj diff --git a/MotorPlant/MotorPlant.sln b/MotorPlant/MotorPlant.sln index bccd19f..74ea2c0 100644 --- a/MotorPlant/MotorPlant.sln +++ b/MotorPlant/MotorPlant.sln @@ -8,9 +8,10 @@ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantDataModels", "MotorPlantDataModels\MotorPlantDataModels.csproj", "{BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantContracts", "MotorPlantContracts\MotorPlantContracts.csproj", "{29205916-9BE6-4349-9131-79573670D7DB}" - ProjectSection(ProjectDependencies) = postProject - {BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B} = {BF6606D4-C24E-4CC6-BA24-E505AB2BCC6B} - EndProjectSection +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantBusinessLogics", "MotorPlantBusinessLogics\MotorPlantBusinessLogics.csproj", "{438B62AC-624E-4457-844C-9C4C257DD223}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MotorPlantListImplement", "MotorPlantListImplement\MotorPlantListImplement.csproj", "{BC88368B-CBE2-420A-BD30-164216769F80}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -30,6 +31,14 @@ Global {29205916-9BE6-4349-9131-79573670D7DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {29205916-9BE6-4349-9131-79573670D7DB}.Release|Any CPU.Build.0 = Release|Any CPU + {438B62AC-624E-4457-844C-9C4C257DD223}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {438B62AC-624E-4457-844C-9C4C257DD223}.Debug|Any CPU.Build.0 = Debug|Any CPU + {438B62AC-624E-4457-844C-9C4C257DD223}.Release|Any CPU.ActiveCfg = Release|Any CPU + {438B62AC-624E-4457-844C-9C4C257DD223}.Release|Any CPU.Build.0 = Release|Any CPU + {BC88368B-CBE2-420A-BD30-164216769F80}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC88368B-CBE2-420A-BD30-164216769F80}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC88368B-CBE2-420A-BD30-164216769F80}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BC88368B-CBE2-420A-BD30-164216769F80}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/ComponentLogic.cs b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..5fc5b80 --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using MotorPlantContracts.StoragesContracts; +using Microsoft.Extensions.Logging; + +namespace MotorPlantBusinessLogics.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + + private readonly IComponentStorage _componentStorage; + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}. Cost:{Cost}. Id:{Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/EngineLogic.cs b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/EngineLogic.cs new file mode 100644 index 0000000..c63d807 --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/EngineLogic.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantBusinessLogics.BusinessLogics +{ + public class EngineLogic : IEngineLogic + { + public bool Create(EngineBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(EngineBindingModel model) + { + throw new NotImplementedException(); + } + + public EngineViewModel? ReadElement(EngineSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(EngineSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(EngineBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/OrderLogic.cs b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..ef73f1a --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogics/BusinessLogics/OrderLogic.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantBusinessLogics.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + public bool CreateOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public bool FinishOrder(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(OrderSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/MotorPlant/MotorPlantBusinessLogics/MotorPlantBusinessLogics.csproj b/MotorPlant/MotorPlantBusinessLogics/MotorPlantBusinessLogics.csproj new file mode 100644 index 0000000..5b21394 --- /dev/null +++ b/MotorPlant/MotorPlantBusinessLogics/MotorPlantBusinessLogics.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/MotorPlant/MotorPlantContracts/BindingModels/ProductBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/EngineBindingModel.cs similarity index 58% rename from MotorPlant/MotorPlantContracts/BindingModels/ProductBindingModel.cs rename to MotorPlant/MotorPlantContracts/BindingModels/EngineBindingModel.cs index 31ae477..fabbd72 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/ProductBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/EngineBindingModel.cs @@ -7,14 +7,14 @@ using MotorPlantDataModels.Models; namespace MotorPlantContracts.BindingModels { - public class ProductBindingModel : IProductModel + public class EngineBindingModel : IEngineModel { public int Id { get; set; } - public string ProductName { get; set; } = string.Empty; + public string EngineName { get; set; } = string.Empty; public double Price { get; set; } - public Dictionary ProductComponents { get; set; } = new(); + public Dictionary EngineComponents { get; set; } = new(); } } diff --git a/MotorPlant/MotorPlantContracts/BindingModels/OrderBindingModel.cs b/MotorPlant/MotorPlantContracts/BindingModels/OrderBindingModel.cs index d4d1a8e..6a4641c 100644 --- a/MotorPlant/MotorPlantContracts/BindingModels/OrderBindingModel.cs +++ b/MotorPlant/MotorPlantContracts/BindingModels/OrderBindingModel.cs @@ -12,7 +12,7 @@ namespace MotorPlantContracts.BindingModels { public int Id { get; set; } - public int ProductId { get; set; } + public int EngineId { get; set; } public int Count { get; set; } diff --git a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IProductLogic.cs b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IEngineLogic.cs similarity index 50% rename from MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IProductLogic.cs rename to MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IEngineLogic.cs index de8b676..485b052 100644 --- a/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IProductLogic.cs +++ b/MotorPlant/MotorPlantContracts/BusinessLogicsContracts/IEngineLogic.cs @@ -9,16 +9,16 @@ using MotorPlantContracts.ViewModels; namespace MotorPlantContracts.BusinessLogicsContracts { - public interface IProductLogic + public interface IEngineLogic { - List? ReadList(ProductSearchModel? model); + List? ReadList(EngineSearchModel? model); - ProductViewModel? ReadElement(ProductSearchModel model); + EngineViewModel? ReadElement(EngineSearchModel model); - bool Create(ProductBindingModel model); + bool Create(EngineBindingModel model); - bool Update(ProductBindingModel model); + bool Update(EngineBindingModel model); - bool Delete(ProductBindingModel model); + bool Delete(EngineBindingModel model); } } diff --git a/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj b/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj index 27ac386..a8fd9eb 100644 --- a/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj +++ b/MotorPlant/MotorPlantContracts/MotorPlantContracts.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/MotorPlant/MotorPlantContracts/SearchModels/ProductSearchModel.cs b/MotorPlant/MotorPlantContracts/SearchModels/EngineSearchModel.cs similarity index 71% rename from MotorPlant/MotorPlantContracts/SearchModels/ProductSearchModel.cs rename to MotorPlant/MotorPlantContracts/SearchModels/EngineSearchModel.cs index 0afdd1a..4058c71 100644 --- a/MotorPlant/MotorPlantContracts/SearchModels/ProductSearchModel.cs +++ b/MotorPlant/MotorPlantContracts/SearchModels/EngineSearchModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace MotorPlantContracts.SearchModels { - public class ProductSearchModel + public class EngineSearchModel { public int? Id { get; set; } - public string? ProductName { get; set; } + public string? EngineName { get; set; } } } diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs new file mode 100644 index 0000000..d4355cf --- /dev/null +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantContracts.StoragesContracts +{ + public interface IEngineStorage + { + List GetFullList(); + + List GetFilteredList(EngineSearchModel model); + + EngineViewModel? GetElement(EngineSearchModel model); + + EngineViewModel? Insert(EngineBindingModel model); + + EngineViewModel? Update(EngineBindingModel model); + + EngineViewModel? Delete(EngineBindingModel model); + } +} diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IProductStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IProductStorage.cs deleted file mode 100644 index 14f801a..0000000 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IProductStorage.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; -using MotorPlantContracts.SearchModels; -using MotorPlantContracts.ViewModels; - -namespace MotorPlantContracts.StoragesContracts -{ - public interface IProductStorage - { - List GetFullList(); - - List GetFilteredList(ProductSearchModel model); - - ProductViewModel? GetElement(ProductSearchModel model); - - ProductViewModel? Insert(ProductBindingModel model); - - ProductViewModel? Update(ProductBindingModel model); - - ProductViewModel? Delete(ProductBindingModel model); - } -} diff --git a/MotorPlant/MotorPlantContracts/ViewModels/ProductViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs similarity index 66% rename from MotorPlant/MotorPlantContracts/ViewModels/ProductViewModel.cs rename to MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs index 8e76790..6853f22 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/ProductViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/EngineViewModel.cs @@ -8,16 +8,16 @@ using System.ComponentModel; namespace MotorPlantContracts.ViewModels { - public class ProductViewModel : IProductModel + public class EngineViewModel : IEngineModel { public int Id { get; set; } [DisplayName("Название изделия")] - public string ProductName { get; set; } = string.Empty; + public string EngineName { get; set; } = string.Empty; [DisplayName("Цена")] public double Price { get; set; } - public Dictionary ProductComponents { get; set; } = new(); + public Dictionary EngineComponents { get; set; } = new(); } } diff --git a/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs b/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs index 650d82c..6bc9c2e 100644 --- a/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs +++ b/MotorPlant/MotorPlantContracts/ViewModels/OrderViewModel.cs @@ -14,10 +14,10 @@ namespace MotorPlantContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } - public int ProductId { get; set; } + public int EngineId { get; set; } [DisplayName("Изделие")] - public string ProductName { get; set; } = string.Empty; + public string EngineName { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } diff --git a/MotorPlant/MotorPlantDataModels/Models/IProductModel.cs b/MotorPlant/MotorPlantDataModels/Models/IEngineModel.cs similarity index 57% rename from MotorPlant/MotorPlantDataModels/Models/IProductModel.cs rename to MotorPlant/MotorPlantDataModels/Models/IEngineModel.cs index 2505b83..7bfbc4d 100644 --- a/MotorPlant/MotorPlantDataModels/Models/IProductModel.cs +++ b/MotorPlant/MotorPlantDataModels/Models/IEngineModel.cs @@ -6,13 +6,13 @@ using System.Threading.Tasks; namespace MotorPlantDataModels.Models { - public interface IProductModel : IId + public interface IEngineModel : IId { - string ProductName { get; } + string EngineName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary EngineComponents { get; } } } diff --git a/MotorPlant/MotorPlantDataModels/Models/IOrderModel.cs b/MotorPlant/MotorPlantDataModels/Models/IOrderModel.cs index 5b9f4f4..1ea0560 100644 --- a/MotorPlant/MotorPlantDataModels/Models/IOrderModel.cs +++ b/MotorPlant/MotorPlantDataModels/Models/IOrderModel.cs @@ -9,7 +9,7 @@ namespace MotorPlantDataModels.Models { public interface IOrderModel : IId { - int ProductId { get; } + int EngineId { get; } int Count { get; } diff --git a/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..b23dcbe --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,114 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; +using MotorPlantListImplement.Models; + +namespace MotorPlantListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs new file mode 100644 index 0000000..58c41e3 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantListImplement.Implements +{ + public class EngineLogic : IEngineLogic + { + public bool Create(EngineBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(EngineBindingModel model) + { + throw new NotImplementedException(); + } + + public EngineViewModel? ReadElement(EngineSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(EngineSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(EngineBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..106787c --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantContracts.ViewModels; + +namespace MotorPlantListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? Delete(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFilteredList(OrderSearchModel model) + { + throw new NotImplementedException(); + } + + public List GetFullList() + { + throw new NotImplementedException(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + throw new NotImplementedException(); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/Models/Component.cs b/MotorPlant/MotorPlantListImplement/Models/Component.cs new file mode 100644 index 0000000..5f02611 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Models/Component.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using AMotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; + +namespace MotorPlantListImplement.Models +{ + internal class Component : IComponentModel + { + public int Id { get; private set; } + + public string ComponentName { get; private set; } = string.Empty; + + public double Cost { get; set; } + + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} diff --git a/MotorPlant/MotorPlantListImplement/Models/Engine.cs b/MotorPlant/MotorPlantListImplement/Models/Engine.cs new file mode 100644 index 0000000..d3d2f01 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Models/Engine.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; + +namespace MotorPlantListImplement.Models +{ + + internal class Engine : IEngineModel + { + public int Id { get; private set; } + + public string EngineName { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public Dictionary EngineComponents { get; private set; } = new Dictionary(); + + public static Engine? Create(EngineBindingModel? model) + { + if (model == null) + { + return null; + } + return new Engine() + { + Id = model.Id, + EngineName = model.EngineName, + Price = model.Price, + EngineComponents = model.EngineComponents + }; + } + + public void Update(EngineBindingModel? model) + { + if (model == null) + { + return; + } + EngineName = model.EngineName; + Price = model.Price; + EngineComponents = model.EngineComponents; + } + + public EngineViewModel GetViewModel => new() + { + Id = Id, + EngineName = EngineName, + Price = Price, + EngineComponents = EngineComponents + }; + } +} diff --git a/MotorPlant/MotorPlantListImplement/Models/Order.cs b/MotorPlant/MotorPlantListImplement/Models/Order.cs new file mode 100644 index 0000000..80f1097 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/Models/Order.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MotorPlantContracts.BindingModels; +using AMotorPlantContracts.ViewModels; +using MotorPlantDataModels.Models; +using MotorPlantDataModels.Enums; + +namespace MotorPlantListImplement.Models +{ + internal class Order : IOrderModel + { + public int ProductId => throw new NotImplementedException(); + + public int Count => throw new NotImplementedException(); + + public double Sum => throw new NotImplementedException(); + + public OrderStatus Status => throw new NotImplementedException(); + + public DateTime DateCreate => throw new NotImplementedException(); + + public DateTime? DateImplement => throw new NotImplementedException(); + + public int Id => throw new NotImplementedException(); + + public static Order? Create(OrderBindingModel? model) + { + return new Order(); + } + + public void Update(OrderBindingModel? model) + { + + } + + public OrderViewModel GetViewModel => new() + { + }; + } +} diff --git a/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj new file mode 100644 index 0000000..4da00b3 --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/MotorPlantListImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +