From 89ed721d723d91b024b647a828de2df621a8b91b Mon Sep 17 00:00:00 2001 From: frog24 Date: Sat, 10 Feb 2024 02:12:37 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=2019=20=D1=81=D1=82=D1=80;=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D1=82=D1=8C=D1=81=D1=8F=20=D1=81=20wit?= =?UTF-8?q?hParams=20+=20=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=B4=D0=B0(=3F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComputersShop/ComputersShop.sln | 14 ++- .../BusinessLogics/ComponentLogic.cs | 112 +++++++++++++++++ .../BusinessLogics/ComputerLogic.cs | 112 +++++++++++++++++ .../BusinessLogics/OrderLogic.cs | 115 ++++++++++++++++++ .../ComputersShopBusinessLogic.csproj | 17 +++ .../BindingModels/ComponentBindingModel.cs | 16 +++ .../BindingModels/ComputerBindingModel.cs | 17 +++ .../BindingModels/OrderBindingModel.cs | 21 ++++ .../IComponentLogic.cs | 20 +++ .../BuisnessLogicsContracts/IComputerLogic.cs | 20 +++ .../BuisnessLogicsContracts/IOrderLogic.cs | 20 +++ .../ComputersShopContracts.csproj | 13 ++ .../SearchModels/ComponentSearchModel.cs | 14 +++ .../SearchModels/ComputerSearchModel.cs | 14 +++ .../SearchModels/OrderSearchModel.cs | 13 ++ .../StoragesContracts/IComponentStorage.cs | 21 ++++ .../StoragesContracts/IComputerStorage.cs | 21 ++++ .../StoragesContracts/IOrderStorage.cs | 21 ++++ .../ViewModels/ComponentViewModel.cs | 20 +++ .../ViewModels/ComputerViewModel.cs | 23 ++++ .../ViewModels/OrderViewModel.cs | 37 ++++++ .../{IProductModel.cs => IComputerModel.cs} | 6 +- .../Models/IOrderModel.cs | 2 +- 23 files changed, 684 insertions(+), 5 deletions(-) create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs create mode 100644 ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs create mode 100644 ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComponentLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComputerLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IOrderLogic.cs create mode 100644 ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs create mode 100644 ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs rename ComputersShop/ComputersShopDataModels/Models/{IProductModel.cs => IComputerModel.cs} (57%) diff --git a/ComputersShop/ComputersShop.sln b/ComputersShop/ComputersShop.sln index 40e6ba9..eb41921 100644 --- a/ComputersShop/ComputersShop.sln +++ b/ComputersShop/ComputersShop.sln @@ -5,7 +5,11 @@ VisualStudioVersion = 17.5.33627.172 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShop", "ComputersShop\ComputersShop.csproj", "{C3280008-18FB-4481-B3A7-6C8534EDC65C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopDataModels", "ComputersShopDataModels\ComputersShopDataModels.csproj", "{34C63637-6E52-4576-99D5-DA7524F73EA0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputersShopDataModels", "ComputersShopDataModels\ComputersShopDataModels.csproj", "{34C63637-6E52-4576-99D5-DA7524F73EA0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopContracts", "ComputersShopContracts\ComputersShopContracts.csproj", "{1761A1DB-696C-4C00-B05F-FD00E768594B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputersShopBusinessLogic", "ComputersShopBusinessLogic\ComputersShopBusinessLogic.csproj", "{93D47C23-DA56-4179-8918-9D70A1012048}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +25,14 @@ Global {34C63637-6E52-4576-99D5-DA7524F73EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU {34C63637-6E52-4576-99D5-DA7524F73EA0}.Release|Any CPU.ActiveCfg = Release|Any CPU {34C63637-6E52-4576-99D5-DA7524F73EA0}.Release|Any CPU.Build.0 = Release|Any CPU + {1761A1DB-696C-4C00-B05F-FD00E768594B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1761A1DB-696C-4C00-B05F-FD00E768594B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1761A1DB-696C-4C00-B05F-FD00E768594B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1761A1DB-696C-4C00-B05F-FD00E768594B}.Release|Any CPU.Build.0 = Release|Any CPU + {93D47C23-DA56-4179-8918-9D70A1012048}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {93D47C23-DA56-4179-8918-9D70A1012048}.Debug|Any CPU.Build.0 = Debug|Any CPU + {93D47C23-DA56-4179-8918-9D70A1012048}.Release|Any CPU.ActiveCfg = Release|Any CPU + {93D47C23-DA56-4179-8918-9D70A1012048}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..466e94c --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,112 @@ +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.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.GetFiltredList(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/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs new file mode 100644 index 0000000..1f8ff51 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/ComputerLogic.cs @@ -0,0 +1,112 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class ComputerLogic: IComputerLogic + { + private readonly ILogger _logger; + private readonly IComputerStorage _computerStorage; + public ComputerLogic(ILogger logger, IComputerStorage computerStorage) + { + _logger = logger; + _computerStorage = computerStorage; + } + public List? ReadList(ComputerSearchModel? model) + { + _logger.LogInformation("ReadList. ComputerName:{ComputerName}. Id:{Id}", model?.ComputerName, model?.Id); + var list = model == null ? _computerStorage.GetFullList() : _computerStorage.GetFiltredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComputerViewModel? ReadElement(ComputerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComputerName:{ComputerName}. Id:{Id}", model.ComputerName, model.Id); + var element = _computerStorage.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(ComputerBindingModel model) + { + CheckModel(model); + if (_computerStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComputerBindingModel model) + { + CheckModel(model); + if (_computerStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComputerBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_computerStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComputerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComputerName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComputerName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Computer. ComputerName:{ComputerName}. Cost:{Cost}. Id:{Id}", model.ComputerName, model.Price, model.Id); + var element = _computerStorage.GetElement(new ComputerSearchModel + { + ComputerName = model.ComputerName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..6248302 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,115 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.BuisnessLogicsContracts; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.StoragesContracts; +using ComputersShopContracts.ViewModels; +using ComputersShopDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopBusinessLogic.BusinessLogics +{ + public class OrderLogic: IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFiltredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Wrong order status. Insert operation failed"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Принят) + { + _logger.LogWarning("Wrong order status. Update operation failed"); + return false; + } + model.Status = OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Выполняется) + { + _logger.LogWarning("Wrong order status. Update operation failed"); + return false; + } + model.Status = OrderStatus.Готов; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool DeliveryOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Готов) + { + _logger.LogWarning("Wrong order status. Update operation failed"); + return false; + } + model.Status = OrderStatus.Выдан; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum) + } + } +} diff --git a/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj new file mode 100644 index 0000000..9254d93 --- /dev/null +++ b/ComputersShop/ComputersShopBusinessLogic/ComputersShopBusinessLogic.csproj @@ -0,0 +1,17 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..33ffc06 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class ComponentBindingModel: IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs new file mode 100644 index 0000000..1aa87d1 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/ComputerBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class ComputerBindingModel: IComputerModel + { + public int Id { get; set; } + public string ComputerName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary ComputerComponents { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..3191bd0 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.BindingModels +{ + public class OrderBindingModel: IOrderModel + { + public int Id { get; set; } + public int ComputerId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComponentLogic.cs b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComponentLogic.cs new file mode 100644 index 0000000..f62ee91 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComponentLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComputerLogic.cs b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComputerLogic.cs new file mode 100644 index 0000000..507bb20 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IComputerLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IComputerLogic + { + List? ReadList(ComputerSearchModel? model); + ComputerViewModel? ReadElement(ComputerSearchModel model); + bool Create(ComputerBindingModel model); + bool Update(ComputerBindingModel model); + bool Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IOrderLogic.cs b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IOrderLogic.cs new file mode 100644 index 0000000..d6b2930 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/BuisnessLogicsContracts/IOrderLogic.cs @@ -0,0 +1,20 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.BuisnessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + bool FinishOrder(OrderBindingModel model); + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj new file mode 100644 index 0000000..9c95599 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ComputersShopContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs new file mode 100644 index 0000000..612b030 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs new file mode 100644 index 0000000..9ad1e0a --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/ComputerSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class ComputerSearchModel + { + public int? Id { get; set; } + public string? ComputerName { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs new file mode 100644 index 0000000..4f909d0 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/SearchModels/OrderSearchModel.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.SearchModels +{ + public class OrderSearchModel + { + public int? Id { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..9455b33 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,21 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFiltredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs new file mode 100644 index 0000000..f1a5e78 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IComputerStorage.cs @@ -0,0 +1,21 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IComputerStorage + { + List GetFullList(); + List GetFiltredList(ComputerSearchModel model); + ComputerViewModel? GetElement(ComputerSearchModel model); + ComputerViewModel? Insert(ComputerBindingModel model); + ComputerViewModel? Update(ComputerBindingModel model); + ComputerViewModel? Delete(ComputerBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..a1bc85f --- /dev/null +++ b/ComputersShop/ComputersShopContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using ComputersShopContracts.BindingModels; +using ComputersShopContracts.SearchModels; +using ComputersShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFiltredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..b6277e3 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.ViewModels +{ + public class ComponentViewModel: IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs new file mode 100644 index 0000000..6e35fda --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/ComputerViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ComputersShopDataModels.Models; + +namespace ComputersShopContracts.ViewModels +{ + public class ComputerViewModel: IComputerModel + { + public int Id { get; set; } + + [DisplayName("Название изделия")] + public string ComputerName { get; set; } = string.Empty; + + [DisplayName("Цена")] + public double Price { get; set; } + + public Dictionary ComputerComponents { get; set; } = new(); + } +} diff --git a/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..21522a9 --- /dev/null +++ b/ComputersShop/ComputersShopContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,37 @@ +using ComputersShopDataModels.Enums; +using ComputersShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputersShopContracts.ViewModels +{ + public class OrderViewModel: IOrderModel + { + [DisplayName("Номер")] + public int Id { get; set; } + + public int ComputerId { get; set; } + + [DisplayName("Изделие")] + public string ComputerName { get; set; } = string.Empty; + + [DisplayName("Количество")] + public int Count { get; set; } + + [DisplayName("Сумма")] + public double Sum { get; set; } + + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/ComputersShop/ComputersShopDataModels/Models/IProductModel.cs b/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs similarity index 57% rename from ComputersShop/ComputersShopDataModels/Models/IProductModel.cs rename to ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs index 57ba5e6..132eb5c 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IProductModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IComputerModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace ComputersShopDataModels.Models { - public interface IProductModel: IId + public interface IComputerModel: IId { - string ProductName { get; } + string ComputerName { get; } double Price { get; } - Dictionary ProductComponents { get; } + Dictionary ComputerComponents { get; } } } diff --git a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs index 21379c4..0380688 100644 --- a/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs +++ b/ComputersShop/ComputersShopDataModels/Models/IOrderModel.cs @@ -9,7 +9,7 @@ namespace ComputersShopDataModels.Models { public interface IOrderModel: IId { - int ProductId { get; } + int ComputerId { get; } int Count { get; } double Sum { get; } OrderStatus Status { get; }