diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..2066fe3 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,106 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.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. EmployeeName:{EmployeeName}. Id:{Id}", model?.EmployeeName, 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. EmployeeName:{EmployeeName}. Id:{Id}", model.EmployeeName, 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.EmployeeName)) + { + throw new ArgumentNullException("Нет названия материала", nameof(model.EmployeeName)); + } + _logger.LogInformation("Employee. EmployeeName:{EmployeeName}. PositionID:{PositionID}. Id:{Id}", model.EmployeeName, model.PositionID, model.Id); + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeOrderLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeOrderLogic.cs new file mode 100644 index 0000000..2afa4c2 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/EmployeeOrderLogic.cs @@ -0,0 +1,92 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.BusinessLogics +{ + public class EmployeeOrderLogic : IEmployeeOrderLogic + { + private readonly ILogger _logger; + private readonly IEmployeeOrderStorage _employeeOrderStorage; + + public EmployeeOrderLogic(ILogger logger, IEmployeeOrderStorage employeeOrderStorage) + { + _logger = logger; + _employeeOrderStorage = employeeOrderStorage; + } + + public List? ReadList(EmployeeOrderSearchModel? model) + { + _logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId); + var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadList. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId); + var element = _employeeOrderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId); + return element; + } + + public bool Create(EmployeeOrderBindingModel model) + { + CheckModel(model); + if (_employeeOrderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(EmployeeOrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId); + if (_employeeOrderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(EmployeeOrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + _logger.LogInformation("EmployeeOrder. EmployeeId:{EmployeeId}. OrderId:{OrderId}", model?.EmployeeId, model?.OrderId); + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialOrderLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialOrderLogic.cs new file mode 100644 index 0000000..03f9444 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialOrderLogic.cs @@ -0,0 +1,96 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.BusinessLogics +{ + public class MaterialOrderLogic : IMaterialOrderLogic + { + private readonly ILogger _logger; + private readonly IMaterialOrderStorage _employeeOrderStorage; + + public MaterialOrderLogic(ILogger logger, IMaterialOrderStorage employeeOrderStorage) + { + _logger = logger; + _employeeOrderStorage = employeeOrderStorage; + } + + public List? ReadList(MaterialOrderSearchModel? model) + { + _logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId); + var list = model == null ? _employeeOrderStorage.GetFullList() : _employeeOrderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadList. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId); + var element = _employeeOrderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId); + return element; + } + + public bool Create(MaterialOrderBindingModel model) + { + CheckModel(model); + if (_employeeOrderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(MaterialOrderBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId); + if (_employeeOrderStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(MaterialOrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Quantity <= 0) + { + throw new InvalidOperationException("Количество должна быть больше 0!"); + } + _logger.LogInformation("MaterialOrder. MaterialId:{MaterialId}. OrderId:{OrderId}", model?.MaterialId, model?.OrderId); + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..fee1795 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs @@ -0,0 +1,121 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.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. Adress:{Adress}. Id:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _orderStorage.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 CreateOrder(OrderBindingModel model) + { + CheckModel(model); + model.Status = ConstructionCompanyDataModels.Enums.OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + CheckModel(model); + model.Status = ConstructionCompanyDataModels.Enums.OrderStatus.Выполняется; + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool FinishOrder(OrderBindingModel model) + { + CheckModel(model); + model.Status = ConstructionCompanyDataModels.Enums.OrderStatus.Завершён; + model.DateEnd = DateTime.Now; + 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 (string.IsNullOrEmpty(model.Description)) + { + throw new ArgumentNullException("Нет описания заказа", nameof(model.Description)); + } + if (string.IsNullOrEmpty(model.Adress)) + { + throw new ArgumentNullException("Нет адреса заказа", nameof(model.Adress)); + } + if (model.Price <= 0) + { + throw new InvalidOperationException("Цена должна быть больше 0!"); + } + if (string.IsNullOrEmpty(model.CustomerNumber)) + { + throw new ArgumentNullException("Нет телефона", nameof(model.CustomerNumber)); + } + + _logger.LogInformation("Order. Description:{Description}. Adress:{Adress}. Price:{Price} Id:{Id}", model.Description, model.Adress, model.Price, model.Id); + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/PositionLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/PositionLogic.cs new file mode 100644 index 0000000..ec60b8e --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/PositionLogic.cs @@ -0,0 +1,110 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.BusinessLogics +{ + public class PositionLogic : IPositionLogic + { + private readonly ILogger _logger; + private readonly IPositionStorage _positionStorage; + + public PositionLogic(ILogger logger, IPositionStorage positionStorage) + { + _logger = logger; + _positionStorage = positionStorage; + } + + public List? ReadList(PositionSearchModel? model) + { + _logger.LogInformation("ReadList. PositionName:{PositionName}. Id:{Id}", model?.PositionName, model?.Id); + var list = model == null ? _positionStorage.GetFullList() : _positionStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public PositionViewModel? ReadElement(PositionSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. PositionName:{PositionName}. Id:{Id}", model.PositionName, model.Id); + var element = _positionStorage.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(PositionBindingModel model) + { + CheckModel(model); + if (_positionStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(PositionBindingModel model) + { + CheckModel(model); + if (_positionStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PositionBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_positionStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(PositionBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PositionName)) + { + throw new ArgumentNullException("Нет названия материала", nameof(model.PositionName)); + } + if (model.Salary < 0) + { + throw new ArgumentNullException("Зарплата должна быть не меньше 0!", nameof(model.Salary)); + } + _logger.LogInformation("Position. IngredietnName:{PositionName}. Salary:{Salary}. Id:{Id}", model.PositionName, model.Salary, model.Id); + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IEmployeeOrderLogic.cs b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IEmployeeOrderLogic.cs index f16df49..9a1f30c 100644 --- a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IEmployeeOrderLogic.cs +++ b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IEmployeeOrderLogic.cs @@ -14,7 +14,6 @@ namespace ConstructionCompanyContracts.BusinessLogicContracts List? ReadList(EmployeeOrderSearchModel? model); EmployeeOrderViewModel? ReadElement(EmployeeOrderSearchModel model); bool Create(EmployeeOrderBindingModel model); - bool Update(EmployeeOrderBindingModel model); bool Delete(EmployeeOrderBindingModel model); } } diff --git a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialOrderLogic.cs b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialOrderLogic.cs index cced54a..d1dbd6d 100644 --- a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialOrderLogic.cs +++ b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialOrderLogic.cs @@ -14,7 +14,6 @@ namespace ConstructionCompanyContracts.BusinessLogicContracts List? ReadList(MaterialOrderSearchModel? model); MaterialOrderViewModel? ReadElement(MaterialOrderSearchModel model); bool Create(MaterialOrderBindingModel model); - bool Update(MaterialOrderBindingModel model); bool Delete(MaterialOrderBindingModel model); } }