From b3ba001d8094593366652c38276f3d7d45bf7156 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B0=D1=82=20=D0=97=D0=B0=D1=80=D0=B3?= =?UTF-8?q?=D0=B0=D1=80=D0=BE=D0=B2?= Date: Mon, 10 Apr 2023 01:14:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20+=20=D0=BE=D1=82=D1=87=D1=91?= =?UTF-8?q?=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CarCenter/CarCenter.sln | 8 +- .../BusinessLogics/BossLogic.cs | 123 +++++++++++++++++ .../BusinessLogics/CarLogic.cs | 106 +++++++++++++++ .../BusinessLogics/ConfigurationLogic.cs | 104 +++++++++++++++ .../BusinessLogics/EmployeeLogic.cs | 126 ++++++++++++++++++ .../BusinessLogics/PresaleLogic.cs | 110 +++++++++++++++ .../BusinessLogics/ReceiptLogic.cs | 112 ++++++++++++++++ .../BusinessLogics/ReportLogic.cs | 110 +++++++++++++++ .../BusinessLogics/SaleLogic.cs | 106 +++++++++++++++ .../BusinessLogics/TypeOfJobLogic.cs | 107 +++++++++++++++ .../CarCenterBusinessLogic.csproj | 18 +++ .../BindingModels/ReportBindingModel.cs | 14 ++ .../BusinessLogicsContracts/IReportLogic.cs | 17 +++ .../ViewModels/ReportCarReceiptViewModel.cs | 15 +++ .../ViewModels/ReportSaleReceiptViewModel.cs | 15 +++ 15 files changed, 1090 insertions(+), 1 deletion(-) create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/ConfigurationLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/BusinessLogics/TypeOfJobLogic.cs create mode 100644 CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj create mode 100644 CarCenter/CarCenterContracts/BindingModels/ReportBindingModel.cs create mode 100644 CarCenter/CarCenterContracts/BusinessLogicsContracts/IReportLogic.cs create mode 100644 CarCenter/CarCenterContracts/ViewModels/ReportCarReceiptViewModel.cs create mode 100644 CarCenter/CarCenterContracts/ViewModels/ReportSaleReceiptViewModel.cs diff --git a/CarCenter/CarCenter.sln b/CarCenter/CarCenter.sln index b486687..bfc67a5 100644 --- a/CarCenter/CarCenter.sln +++ b/CarCenter/CarCenter.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDataModels", "CarC EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterDatabaseImplement", "CarCenterDatabaseImplement\CarCenterDatabaseImplement.csproj", "{84503674-1555-4ED9-89C4-385C76F6B89C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterView", "CarCenterView\CarCenterView.csproj", "{A9F57191-CEAF-4164-87A5-73C2C9245D75}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCenterView", "CarCenterView\CarCenterView.csproj", "{A9F57191-CEAF-4164-87A5-73C2C9245D75}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCenterBusinessLogic", "CarCenterBusinessLogic\CarCenterBusinessLogic.csproj", "{398B3328-DCC8-4D51-95AB-913D3FDECCF4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -33,6 +35,10 @@ Global {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Debug|Any CPU.Build.0 = Debug|Any CPU {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.ActiveCfg = Release|Any CPU {A9F57191-CEAF-4164-87A5-73C2C9245D75}.Release|Any CPU.Build.0 = Release|Any CPU + {398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {398B3328-DCC8-4D51-95AB-913D3FDECCF4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs new file mode 100644 index 0000000..4372e0a --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/BossLogic.cs @@ -0,0 +1,123 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using CarCenterContracts.StoragesContracts; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class BossLogic : IBossLogic + { + private readonly ILogger _logger; + private readonly IBossStorage _BossStorage; + + public BossLogic(ILogger logger, IBossStorage BossStorage) + { + _logger = logger; + _BossStorage = BossStorage; + } + public List? ReadList(BossSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _BossStorage.GetFullList() : _BossStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public BossViewModel? ReadElement(BossSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}. Login: { Login}", model.Id, model.Login); + var element = _BossStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}. Login: { Login}", element.Id); + return element; + } + public bool Create(BossBindingModel model) + { + CheckModel(model); + if (_BossStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(BossBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_BossStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + public bool Update(BossBindingModel model) + { + CheckModel(model); + if (_BossStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(BossBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени начальника!", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии начальника!", nameof(model.Surname)); + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина начальника!", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля начальника!", nameof(model.Password)); + } + _logger.LogInformation("Boss. Surname:{Surname}. Name:{Name}. Login:{Login}. Password:{Password}. Id:{Id}", model.Surname, model.Name, model.Login, model.Password, model.Id); + var element = _BossStorage.GetElement(new BossSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Начальник с таким логином уже есть"); + } + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs new file mode 100644 index 0000000..e9d9bed --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/CarLogic.cs @@ -0,0 +1,106 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class CarLogic : ICarLogic + { + private readonly ILogger _logger; + private readonly ICarStorage _CarStorage; + + public CarLogic(ILogger logger, ICarStorage CarStorage) + { + _logger = logger; + _CarStorage = CarStorage; + } + + public List? ReadList(CarSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _CarStorage.GetFullList() : _CarStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public CarViewModel? ReadElement(CarSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _CarStorage.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(CarBindingModel model) + { + CheckModel(model); + if (_CarStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(CarBindingModel model) + { + CheckModel(model); + if (_CarStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(CarBindingModel model) + { + CheckModel(model); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_CarStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(CarBindingModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия машины!", nameof(model.Name)); + } + if (model.EmployeeId < 0) + { + throw new InvalidOperationException("Неверный ID сотрудника"); + } + _logger.LogInformation("Car. Name:{Name}. EmployeeId:{EmployeeId}. Id:{Id}", model.Name, model.EmployeeId, model.Id); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/ConfigurationLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ConfigurationLogic.cs new file mode 100644 index 0000000..026f10e --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ConfigurationLogic.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class ConfigurationLogic : IConfigurationLogic + { + private readonly ILogger _logger; + private readonly IConfigurationStorage _ConfigurationStorage; + public ConfigurationLogic(ILogger logger, IConfigurationStorage ConfigurationStorage) + { + _logger = logger; + _ConfigurationStorage = ConfigurationStorage; + } + public List? ReadList(ConfigurationSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _ConfigurationStorage.GetFullList() : _ConfigurationStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ConfigurationViewModel? ReadElement(ConfigurationSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _ConfigurationStorage.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(ConfigurationBindingModel model) + { + CheckModel(model); + if (_ConfigurationStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ConfigurationBindingModel model) + { + CheckModel(model); + if (_ConfigurationStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ConfigurationBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ConfigurationStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ConfigurationBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия комплектации!", nameof(model.Name)); + } + if (model.BossId < 0) + { + throw new InvalidOperationException("Id начальника меньше нуля!"); + } + _logger.LogInformation("Configuration. Name:{ Name}. BossId: { BossId}. Id: { Id}", model.Name, model.BossId, model.Id); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..c9f12ce --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,126 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class EmployeeLogic : IEmployeeLogic + { + private readonly ILogger _logger; + private readonly IEmployeeStorage _EmployeeStorage; + + public EmployeeLogic(ILogger logger, IEmployeeStorage EmployeeStorage) + { + _logger = logger; + _EmployeeStorage = EmployeeStorage; + } + + public List? ReadList(EmployeeSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _EmployeeStorage.GetFullList() : _EmployeeStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public EmployeeViewModel? ReadElement(EmployeeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _EmployeeStorage.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(EmployeeBindingModel model) + { + CheckModel(model); + if (_EmployeeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(EmployeeBindingModel model) + { + CheckModel(model); + if (_EmployeeStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(EmployeeBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_EmployeeStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(EmployeeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени сотрудника", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии сотрудника", nameof(model.Surname)); + } + if (string.IsNullOrEmpty(model.Login)) + { + throw new ArgumentNullException("Нет логина сотрудника", nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.Password)); + } + _logger.LogInformation("Employee. Surname:{Surname}. Name:{Name}. Login:{Login}. Password:{Password}. Id:{Id}", model.Surname, model.Name, model.Login, model.Password, model.Id); + var element = _EmployeeStorage.GetElement(new EmployeeSearchModel + { + Login = model.Login + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сотрудник с таким логином уже есть"); + } + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs new file mode 100644 index 0000000..6138b1f --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/PresaleLogic.cs @@ -0,0 +1,110 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterusinessLogic.BusinessLogics +{ + public class PresaleLogic : IPresaleLogic + { + private readonly ILogger _logger; + private readonly IPresaleStorage _PresaleStorage; + + public PresaleLogic(ILogger logger, IPresaleStorage PresaleStorage) + { + _logger = logger; + _PresaleStorage = PresaleStorage; + } + + public List? ReadList(PresaleSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _PresaleStorage.GetFullList() : _PresaleStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PresaleViewModel? ReadElement(PresaleSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _PresaleStorage.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(PresaleBindingModel model) + { + CheckModel(model); + if (_PresaleStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PresaleBindingModel model) + { + CheckModel(model); + if (_PresaleStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(PresaleBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_PresaleStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PresaleBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.TypeOfJobId < 0) + { + throw new InvalidOperationException("Неверный ID вида работы"); + } + if (model.EmployeeId < 0) + { + throw new InvalidOperationException("Неверный ID сотрудника"); + } + _logger.LogInformation("Presale. PresaleDate:{PresaleDate}. TypeOfJobId:{TypeOfJobId}. EmployeeId:{EmployeeId}. Id:{Id}", model.PresaleDate, model.TypeOfJobId, model.EmployeeId, model.Id); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs new file mode 100644 index 0000000..5274d58 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReceiptLogic.cs @@ -0,0 +1,112 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using CarCenterContracts.StoragesContracts; + + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class ReceiptLogic : IReceiptLogic + { + private readonly ILogger _logger; + private readonly IReceiptStorage _ReceiptStorage; + public ReceiptLogic(ILogger logger, IReceiptStorage ReceiptStorage) + { + _logger = logger; + _ReceiptStorage = ReceiptStorage; + } + public ReceiptViewModel? ReadElement(ReceiptSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _ReceiptStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public List? ReadList(ReceiptSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _ReceiptStorage.GetFullList() : _ReceiptStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public bool Create(ReceiptBindingModel model) + { + CheckModel(model); + if (_ReceiptStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(ReceiptBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_ReceiptStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool Update(ReceiptBindingModel model) + { + CheckModel(model); + if (_ReceiptStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(ReceiptBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.BossId < 0) + { + throw new InvalidOperationException("Id начальника меньше нуля!"); + } + if(model.ConfigurationId < 0) + { + throw new InvalidOperationException("Id комплектации меньше нуля!"); + } + if (model.Sum < 0) { + throw new InvalidOperationException("Сумма поступления неверная!"); + } + _logger.LogInformation("Id: {Id}. Sum:{ Sum}. BossId: { BossId}. ConfigurationId: {ConfigurationId}.", model.Id, model.Sum, model.BossId, model.ConfigurationId); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..e779f3b --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,110 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using CarCenterContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly ISaleStorage _saleStorage; + private readonly ICarStorage _carStorage; + private readonly IReceiptStorage _receiptStorage; + private readonly IConfigurationStorage _configurationStorage; + public ReportLogic(ISaleStorage saleStorage, ICarStorage carStorage, IReceiptStorage receiptStorage) + { + _saleStorage = saleStorage; + _carStorage = carStorage; + _receiptStorage = receiptStorage; + } + + + public List GetSaleReceipt(ReportBindingModel model) + { + var sales = _saleStorage.GetFilteredList(new SaleSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); + var configurations = _configurationStorage.GetFullList(); + var receipts = _receiptStorage.GetFullList(); + var list = new List(); + + foreach (var sale in sales) + { + var record = new ReportSaleReceiptViewModel + { + SaleId = sale.Id, + SaleDate = sale.SaleDateTime, + Receipts = new List<(int, float)>() + }; + var car = _carStorage.GetElement(new CarSearchModel { Id = sale.Id }); + if (car == null) + { + throw new InvalidOperationException("Машина не была найден!"); + } + var foundConfigurationsId = new List(); + foreach (var configuration in configurations) + { + if (car.ConfigurationCars.ContainsKey(configuration.Id)) foundConfigurationsId.Add(configuration.Id); + } + foreach (var receipt in receipts) + { + foreach (var configurationId in foundConfigurationsId) + { + if (receipt.ConfigurationId == configurationId) + { + record.Receipts.Add(new(receipt.Id,receipt.Sum)); + break; + } + } + } + list.Add(record); + } + + return list; + } + + public List GetCarReceipt(ReportBindingModel model) + { + var receipts = _receiptStorage.GetFilteredList(new ReceiptSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }); + var list = new List(); + var cars = _carStorage.GetFullList(); + foreach (var receipt in receipts) + { + var record = new ReportCarReceiptViewModel + { + ReceiptId = receipt.Id, + ReceiptDate = receipt.ReceiptDate, + Cars = new List<(int CarId, string CarDate)>(), + }; + foreach (var car in cars) + { + if (car.ConfigurationCars.ContainsKey(receipt.ConfigurationId)) record.Cars.Add(new(car.Id, car.Name.ToString())); + } + list.Add(record); + } + return list; + } + + public void SaveCarReceiptToExcel(List cars) + { + // Создание файла + throw new NotImplementedException(); + } + + public void SaveCarReceiptToWord(List cars) + { + // Создание файла + throw new NotImplementedException(); + } + + public void SaveSaleReceiptToPDF(ReportBindingModel model) + { + // Создание файла + throw new NotImplementedException(); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.cs new file mode 100644 index 0000000..51150cd --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/SaleLogic.cs @@ -0,0 +1,106 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.StoragesContracts; +using CarCenterContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class SaleLogic : ISaleLogic + { + private readonly ILogger _logger; + private readonly ISaleStorage _SaleStorage; + + public SaleLogic(ILogger logger, ISaleStorage SaleStorage) + { + _logger = logger; + _SaleStorage = SaleStorage; + } + + public List? ReadList(SaleSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); + var list = model == null ? _SaleStorage.GetFullList() : _SaleStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public SaleViewModel? ReadElement(SaleSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _SaleStorage.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(SaleBindingModel model) + { + CheckModel(model); + if (_SaleStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(SaleBindingModel model) + { + CheckModel(model); + if (_SaleStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(SaleBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_SaleStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(SaleBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Sum < 0) + { + throw new InvalidOperationException("Сумма не может быть отрицательной"); + } + _logger.LogInformation("Sale. SaleDateTime:{SaleDateTime}. Sum:{Sum}. CarId:{CarId}. ReceiptId:{ReceiptId}. ConfigurationId:{ConfigurationId}. Id:{Id}", model.SaleDateTime, model.Sum, model.CarId, model.ReceiptId, model.ConfigurationId, model.Id); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/BusinessLogics/TypeOfJobLogic.cs b/CarCenter/CarCenterBusinessLogic/BusinessLogics/TypeOfJobLogic.cs new file mode 100644 index 0000000..e851f2a --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/BusinessLogics/TypeOfJobLogic.cs @@ -0,0 +1,107 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.BusinessLogicsContracts; +using CarCenterContracts.SearchModels; +using CarCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using CarCenterContracts.StoragesContracts; + +namespace CarCenterBusinessLogic.BusinessLogics +{ + public class TypeOfJobLogic : ITypeOfJobLogic + { + private readonly ILogger _logger; + private readonly ITypeOfJobStorage _TypeOfJobStorage; + public TypeOfJobLogic(ILogger logger, ITypeOfJobStorage TypeOfJobStorage) + { + _logger = logger; + _TypeOfJobStorage = TypeOfJobStorage; + } + public List? ReadList(TypeOfJobSearchModel? model) + { + _logger.LogInformation("ReadList. Id:{ Id}", model?.Id); + var list = model == null ? _TypeOfJobStorage.GetFullList() : _TypeOfJobStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public TypeOfJobViewModel? ReadElement(TypeOfJobSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{ Id}", model.Id); + var element = _TypeOfJobStorage.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(TypeOfJobBindingModel model) + { + CheckModel(model); + if (_TypeOfJobStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(TypeOfJobBindingModel model) + { + CheckModel(model); + if (_TypeOfJobStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Update(TypeOfJobBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_TypeOfJobStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(TypeOfJobBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия вида работы!", nameof(model.Name)); + } + if (model.BossId < 0) + { + throw new InvalidOperationException("Id начальника меньше нуля!"); + } + _logger.LogInformation("TypeOfJob. Name:{ Name}. BossId: { BossId}. Id: { Id}", model.Name, model.BossId, model.Id); + } + } +} diff --git a/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj b/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj new file mode 100644 index 0000000..57c0687 --- /dev/null +++ b/CarCenter/CarCenterBusinessLogic/CarCenterBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/CarCenter/CarCenterContracts/BindingModels/ReportBindingModel.cs b/CarCenter/CarCenterContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..e9235e8 --- /dev/null +++ b/CarCenter/CarCenterContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterContracts.BindingModels +{ + public class ReportBindingModel + { + public DateTime DateFrom { get; set; } + public DateTime DateTo { get; set; } + } +} diff --git a/CarCenter/CarCenterContracts/BusinessLogicsContracts/IReportLogic.cs b/CarCenter/CarCenterContracts/BusinessLogicsContracts/IReportLogic.cs new file mode 100644 index 0000000..06fc52a --- /dev/null +++ b/CarCenter/CarCenterContracts/BusinessLogicsContracts/IReportLogic.cs @@ -0,0 +1,17 @@ +using CarCenterContracts.BindingModels; +using CarCenterContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterContracts.BusinessLogicsContracts +{ + public interface IReportLogic + { + void SaveCarReceiptToWord(List cars); + void SaveCarReceiptToExcel(List cars); + void SaveSaleReceiptToPDF(ReportBindingModel model); + } +} diff --git a/CarCenter/CarCenterContracts/ViewModels/ReportCarReceiptViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/ReportCarReceiptViewModel.cs new file mode 100644 index 0000000..6f40fec --- /dev/null +++ b/CarCenter/CarCenterContracts/ViewModels/ReportCarReceiptViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterContracts.ViewModels +{ + public class ReportCarReceiptViewModel + { + public int ReceiptId { get; set; } + public DateTime ReceiptDate { get; set; } + public List<(int CarId, string Num)> Cars { get; set; } = new(); + } +} diff --git a/CarCenter/CarCenterContracts/ViewModels/ReportSaleReceiptViewModel.cs b/CarCenter/CarCenterContracts/ViewModels/ReportSaleReceiptViewModel.cs new file mode 100644 index 0000000..26a9c27 --- /dev/null +++ b/CarCenter/CarCenterContracts/ViewModels/ReportSaleReceiptViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCenterContracts.ViewModels +{ + public class ReportSaleReceiptViewModel + { + public int SaleId { get; set; } + public DateTime SaleDate { get; set; } + public List<(int ReceiptId, float Sum)> Receipts { get; set; } = new(); + } +}