diff --git a/Car_Centre/CarCentreBusinessLogic/BusinessLogic/AutoLogic.cs b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/AutoLogic.cs new file mode 100644 index 0000000..fb629af --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/AutoLogic.cs @@ -0,0 +1,138 @@ +using CarCentreContracts.BindingModels; +using CarCentreContracts.BusinessLogicsContracts; +using CarCentreContracts.SearchModels; +using CarCentreContracts.StorageContracts; +using CarCentreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCentreBusinessLogic.BusinessLogic +{ + public class AutoLogic : IAutoLogic + { + private readonly ILogger _logger; + private readonly IAutoStorage _WorkStorage; + + public AutoLogic(ILogger logger, IAutoStorage WorkStorage) + { + _logger = logger; + _WorkStorage = WorkStorage; + } + public List? ReadList(AutoSearchModel? model) + { + _logger.LogInformation("ReadList. AutoName:{WorkName}. Id:{ Id}", model?.AutoName, model?.Id); + var list = model == null ? _WorkStorage.GetFullList() : _WorkStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public AutoViewModel? ReadElement(AutoSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. AutoName:{WorkName}.Id:{ Id}", model.AutoName, model.Id); + var element = _WorkStorage.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(WorkBindingModel model) + { + CheckModel(model); + if (_WorkStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(WorkBindingModel model) + { + CheckModel(model); + if (_WorkStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(WorkBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_WorkStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(WorkBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.AutoPrice <= 0) + { + throw new ArgumentNullException("Cтоимости посещения работаа должна быть больше 0", + nameof(model.AutoPrice)); + } + _logger.LogInformation("Auto. AutoName:{AutoName}.AutoPrice:{AutoPrice} Id: { Id}", model.AutoName, model.AutoPrice, model.Id); + var element = _WorkStorage.GetElement(new AutoSearchModel + { + AutoName = model.AutoName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("работа с таким названием уже есть"); + } + } + + List? IAutoLogic.ReadList(AutoSearchModel? model) + { + throw new NotImplementedException(); + } + + AutoViewModel? IAutoLogic.ReadElement(AutoSearchModel model) + { + throw new NotImplementedException(); + } + + bool IAutoLogic.Create(WorkBindingModel model) + { + throw new NotImplementedException(); + } + + bool IAutoLogic.Update(WorkBindingModel model) + { + throw new NotImplementedException(); + } + + bool IAutoLogic.Delete(WorkBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/Car_Centre/CarCentreBusinessLogic/BusinessLogic/ClientLogic.cs b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..774d56f --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/ClientLogic.cs @@ -0,0 +1,124 @@ +using CarCentreContracts.BindingModels; +using CarCentreContracts.BusinessLogicsContracts; +using CarCentreContracts.SearchModels; +using CarCentreContracts.StorageContracts; +using CarCentreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCentreBusinessLogic.BusinessLogic +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } + + public List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. ClientId:{Id}", model?.Id); + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientFio:{ClientFio}.Id:{ Id}", model.ClientFIO, model.Id); + var element = _clientStorage.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(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_clientStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ClientFIO)) + { + throw new ArgumentNullException("Нет ФИО пользователя", nameof(model.ClientFIO)); + } + if (string.IsNullOrEmpty(model.EMail)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.EMail)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + _logger.LogInformation("Client. ClientFIO:{ClientFIO}.Email:{Email}.Password:{Password}.Id:{Id}", + model.ClientFIO, model.EMail, model.Password, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel + { + ClientFIO = model.ClientFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким именем уже есть"); + } + } + } +} diff --git a/Car_Centre/CarCentreBusinessLogic/BusinessLogic/EmployeeLogic.cs b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/EmployeeLogic.cs new file mode 100644 index 0000000..65770ff --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/EmployeeLogic.cs @@ -0,0 +1,117 @@ +using CarCentreContracts.BindingModels; +using CarCentreContracts.BusinessLogicsContracts; +using CarCentreContracts.SearchModels; +using CarCentreContracts.StorageContracts; +using CarCentreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCentreBusinessLogic.BusinessLogic +{ + public class EmployeeLogic : IEmployeeLogic + { + private readonly ILogger _logger; + private readonly IEmployeeStorage _employeeStorage; + + public EmployeeLogic(Microsoft.Extensions.Logging.ILogger logger, IEmployeeStorage employeeStorage) + { + _logger = logger; + _employeeStorage = employeeStorage; + } + public List? ReadList(EmployeeSearchModel? model) + { + _logger.LogInformation("ReadList. EmployeeFIO:{EmployeeFIO}. Id:{ Id}", model?.EmployeeFIO, 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. EmployeeFIO:{EmployeeFIO}.Id:{ Id}", model.EmployeeFIO, 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.Login)) + { + throw new ArgumentNullException("Нет логина сотрудника", + nameof(model.Login)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password)); + } + _logger.LogInformation("Employee. EmployeeFIO:{EmployeeFIO}.Login:{ Login}.Password:{Password} Id: { Id}", model.EmployeeFIO, model.Login, model.Password, model.Id); + var element = _employeeStorage.GetElement(new EmployeeSearchModel + { + EmployeeFIO = model.EmployeeFIO + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сотрудник с таким логином уже есть"); + } + } + } +} diff --git a/Car_Centre/CarCentreBusinessLogic/BusinessLogic/PaymentLogic.cs b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/PaymentLogic.cs new file mode 100644 index 0000000..cb3d1b6 --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/PaymentLogic.cs @@ -0,0 +1,62 @@ +using CarCentreContracts.BindingModels; +using CarCentreContracts.BusinessLogicsContracts; +using CarCentreContracts.SearchModels; +using CarCentreContracts.StorageContracts; +using CarCentreContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCentreBusinessLogic.BusinessLogic +{ + public class PaymentLogic : IPaymentLogic + { + private readonly ILogger _logger; + private readonly IPaymentStorage _paymentStorage; + public PaymentLogic(ILogger logger, IPaymentStorage paymentStorage) + { + _logger = logger; + _paymentStorage = paymentStorage; + } + public bool Create(PaymentBindingModel model) + { + throw new NotImplementedException(); + } + + public bool Delete(PaymentBindingModel model) + { + throw new NotImplementedException(); + } + + public PaymentViewModel? ReadElement(PaymentSearchModel model) + { + throw new NotImplementedException(); + } + + public List? ReadList(PaymentSearchModel? model) + { + throw new NotImplementedException(); + } + + public bool Update(PaymentBindingModel model) + { + throw new NotImplementedException(); + } + private void CheckModel(RequestBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + _logger.LogInformation("Request. Id: {Id}", model.Id); + } + } + +} diff --git a/Car_Centre/CarCentreBusinessLogic/BusinessLogic/RequestLogic.cs b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/RequestLogic.cs new file mode 100644 index 0000000..9caa8b4 --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/BusinessLogic/RequestLogic.cs @@ -0,0 +1,95 @@ +using CarCentreContracts.BindingModels; +using CarCentreContracts.BusinessLogicsContracts; +using CarCentreContracts.SearchModels; +using CarCentreContracts.StorageContracts; +using CarCentreContracts.ViewModels; +using CarCentreDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CarCentreBusinessLogic.BusinessLogic +{ + public class RequestLogic : IRequestLogic + { + private readonly ILogger _logger; + private readonly IRequestStorage _RequestStorage; + + public RequestLogic(ILogger logger, IRequestStorage RequestStorage) + { + _logger = logger; + _RequestStorage = RequestStorage; + } + public List? ReadList(RequestSearchModel? model) + { + _logger.LogInformation("ReadList. RequestName:{RequestName}. Id:{ Id}", model?.RequestName, model?.Id); + var list = model == null ? _RequestStorage.GetFullList() : _RequestStorage.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(RequestBindingModel model) + { + CheckModel(model); + if (_RequestStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool CheckRequestPay(RequestBindingModel model, RequestStatus status) + { + CheckModel(model); + var element = _RequestStorage.GetElement(new RequestSearchModel { Id = model.Id }); + if (element == null) + { + _logger.LogWarning("Read operation failed"); + return false; + } + if (element.Status != status - 1) + { + _logger.LogWarning("Status change operation failed"); + throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный"); + } + model.Status = status; + if (model.Status == RequestStatus.Неоплачен) model.DateFinish = DateTime.Now; + _RequestStorage.Update(model); + return true; + } + public bool RequestWasPaid(RequestBindingModel model) + { + return CheckRequestPay(model, RequestStatus.Оплачен); + } + private void CheckModel(RequestBindingModel model, bool withParams = + true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.RequestName)) + { + throw new ArgumentNullException("Нет названия сделки", + nameof(model.RequestName)); + } + if (model.RequestPrice <= 0) + { + throw new ArgumentNullException("Стоимость сделки должна быть >0", nameof(model.RequestPrice)); + } + _logger.LogInformation("Request. RequestName:{RequestName}.RequestPrice:{ RequestPrice} Id: { Id}", model.RequestName, model.RequestPrice, model.Id); + } + } +} diff --git a/Car_Centre/CarCentreBusinessLogic/CarCentreBusinessLogic.csproj b/Car_Centre/CarCentreBusinessLogic/CarCentreBusinessLogic.csproj new file mode 100644 index 0000000..a2e73d0 --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/CarCentreBusinessLogic.csproj @@ -0,0 +1,18 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + diff --git a/Car_Centre/CarCentreBusinessLogic/Class1.cs b/Car_Centre/CarCentreBusinessLogic/Class1.cs new file mode 100644 index 0000000..7d6e4d6 --- /dev/null +++ b/Car_Centre/CarCentreBusinessLogic/Class1.cs @@ -0,0 +1,7 @@ +namespace CarCentreBusinessLogic +{ + public class Class1 + { + + } +} diff --git a/Car_Centre/Car_Centre.sln b/Car_Centre/Car_Centre.sln index bffa55a..b7c8a3a 100644 --- a/Car_Centre/Car_Centre.sln +++ b/Car_Centre/Car_Centre.sln @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreDataModels", "CarCentreDataModels\CarCentreDataModels.csproj", "{44ABE0E6-CF7F-4401-8264-CA9278EEE541}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCentreDataModels", "CarCentreDataModels\CarCentreDataModels.csproj", "{44ABE0E6-CF7F-4401-8264-CA9278EEE541}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreContracts", "CarCentreContracts\CarCentreContracts.csproj", "{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarCentreContracts", "CarCentreContracts\CarCentreContracts.csproj", "{C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarCentreBusinessLogic", "CarCentreBusinessLogic\CarCentreBusinessLogic.csproj", "{B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -21,6 +23,10 @@ Global {C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Debug|Any CPU.Build.0 = Debug|Any CPU {C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Release|Any CPU.ActiveCfg = Release|Any CPU {C7B3BF74-07D4-4C4B-948D-EC87F53FC3B3}.Release|Any CPU.Build.0 = Release|Any CPU + {B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4C7F6E2-1506-40F8-A819-5DEB65D0B2CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE