diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln index 537b67b..08fec75 100644 --- a/JewelryStore/JewelryStore.sln +++ b/JewelryStore/JewelryStore.sln @@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", ".. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {84BF2156-F821-46F4-8EED-F371084C0129}.Debug|Any CPU.Build.0 = Debug|Any CPU {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.ActiveCfg = Release|Any CPU {84BF2156-F821-46F4-8EED-F371084C0129}.Release|Any CPU.Build.0 = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA57067F-F3ED-4B1C-B56F-52856FC2E93D}.Release|Any CPU.Build.0 = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..ea507ce --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,117 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; + + +namespace JewelryStoreBusinessLogic.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/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs new file mode 100644 index 0000000..66fe1fa --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/JewelLogic.cs @@ -0,0 +1,40 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class JewelLogic : IJewelLogic // TODO реализовать интерфейс идентично componentLogic + { + public bool Create(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(JewelBindingModel model) + { + throw new NotImplementedException(); + } + + public JewelViewModel? ReadElement(JewelSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(JewelSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(JewelBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..f3a90c2 --- /dev/null +++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,45 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; +using JewelryStoreContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace JewelryStoreBusinessLogic.BusinessLogics +{ + internal class OrderLogic : IOrderLogic //TODO реализовать интерфейс + { +// Класс с логикой для заказов будет отвечать за получение списка заказов, +//создания заказа и смены его статусов.Следует учитывать, что у заказа можно +//менять статус на новый, если его текущий статус предшествует новому +//(например, в статус «Готов» можно переводить, если заказ находится в статусе +//«Выполняется»). + 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/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj new file mode 100644 index 0000000..7e1df35 --- /dev/null +++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/JewelryStoreListImplement/Class1.cs b/JewelryStoreListImplement/Class1.cs new file mode 100644 index 0000000..cdbf310 --- /dev/null +++ b/JewelryStoreListImplement/Class1.cs @@ -0,0 +1,7 @@ +namespace JewelryStoreListImplement +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/JewelryStoreListImplement/JewelryStoreListImplement.csproj b/JewelryStoreListImplement/JewelryStoreListImplement.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/JewelryStoreListImplement/JewelryStoreListImplement.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + +