diff --git a/FurnitureFactory/FurnitureFactory.sln b/FurnitureFactory/FurnitureFactory.sln index e9fd5b5..8a3fbd2 100644 --- a/FurnitureFactory/FurnitureFactory.sln +++ b/FurnitureFactory/FurnitureFactory.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryDataModels" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryContracts", "FurnitureFactoryContracts\FurnitureFactoryContracts.csproj", "{E0818635-0C99-435E-99E5-8241473D0E48}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FurnitureFactoryBusinessLogic", "FurnitureFactoryBusinessLogic\FurnitureFactoryBusinessLogic.csproj", "{F823EC86-06B1-4D50-BD39-85CF213F7A00}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +29,10 @@ Global {E0818635-0C99-435E-99E5-8241473D0E48}.Debug|Any CPU.Build.0 = Debug|Any CPU {E0818635-0C99-435E-99E5-8241473D0E48}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0818635-0C99-435E-99E5-8241473D0E48}.Release|Any CPU.Build.0 = Release|Any CPU + {F823EC86-06B1-4D50-BD39-85CF213F7A00}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F823EC86-06B1-4D50-BD39-85CF213F7A00}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F823EC86-06B1-4D50-BD39-85CF213F7A00}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F823EC86-06B1-4D50-BD39-85CF213F7A00}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ClientLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..375ae6e --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,123 @@ +using Microsoft.Extensions.Logging; +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + 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. ClientFIO:{ClientFIO}. Id:{Id}", model?.ClientFIO, 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.ClientFIO)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля учетной записи клиента", nameof(model.ClientFIO)); + } + _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 + { + Email = model.Email + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким логином уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs new file mode 100644 index 0000000..547e348 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/EmployeeLogic.cs @@ -0,0 +1,129 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class EmployeeLogic : IEmployeeLogic + { + private readonly ILogger _logger; + private readonly IEmployeeStorage _employeeStorage; + public EmployeeLogic(ILogger logger, IEmployeeStorage employeeStorage) + { + _logger = logger; + _employeeStorage = employeeStorage; + } + + public bool Create(EmployeeBindingModel model) + { + CheckModel(model); + if (_employeeStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public EmployeeViewModel? ReadElement(EmployeeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FIO:{FIO}.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 List? ReadList(EmployeeSearchModel? model) + { + _logger.LogInformation("ReadList. FIO:{FIO}.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 bool Update(EmployeeBindingModel model) + { + CheckModel(model); + if (_employeeStorage.Update(model) == null) + { + _logger.LogWarning("Update 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 (model.WorkExperience < 0) + { + throw new ArgumentException("Опыт работы не должен быть отрицательным", nameof(model.WorkExperience)); + } + if (model.Qualification < 0) + { + throw new ArgumentException("Квалификация не должна быть отрицательной", nameof(model.Qualification)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.EmployeeFIO)); + } + if (string.IsNullOrEmpty(model.EmployeeFIO)) + { + throw new ArgumentNullException("Нет фио сотрудника", nameof(model.EmployeeFIO)); + } + _logger.LogInformation("Employee. Id: {Id}, FIO: {FIO}", model.Id, model.EmployeeFIO); + var element = _employeeStorage.GetElement(new EmployeeSearchModel + { + EmployeeFIO = model.EmployeeFIO, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Сотрудник с таким фио уже есть"); + } + } + + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/FurnitureLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/FurnitureLogic.cs new file mode 100644 index 0000000..302c5e6 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/FurnitureLogic.cs @@ -0,0 +1,112 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class FurnitureLogic : IFurnitureLogic + { + private readonly ILogger _logger; + private readonly IFurnitureStorage _furnitureStorage; + public FurnitureLogic(ILogger logger, IFurnitureStorage furnitureStorage) + { + _logger = logger; + _furnitureStorage = furnitureStorage; + } + public List? ReadList(FurnitureSearchModel? model) + { + _logger.LogInformation("ReadList. FurnitureName:{FurnitureName}.Id:{ Id}", model?.FurnitureName, model?.Id); + var list = model == null ? _furnitureStorage.GetFullList() : _furnitureStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public FurnitureViewModel? ReadElement(FurnitureSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. FurnitureName:{FurnitureName}.Id:{ Id}", model.FurnitureName, model.Id); + var element = _furnitureStorage.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(FurnitureBindingModel model) + { + CheckModel(model); + if (_furnitureStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(FurnitureBindingModel model) + { + CheckModel(model); + if (_furnitureStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(FurnitureBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_furnitureStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(FurnitureBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.FurnitureName)) + { + throw new ArgumentNullException("Нет названия мебели", nameof(model.FurnitureName)); + } + if (model.FurniturePrice <= 0) + { + throw new ArgumentNullException("Цена мебели должна быть больше 0", nameof(model.FurniturePrice)); + } + _logger.LogInformation("Furniture. FurnitureName:{FurnitureName}.FurniturePrice:{FurniturePrice}.Id: { Id}", model.FurnitureName, model.FurniturePrice, model.Id); + var element = _furnitureStorage.GetElement(new FurnitureSearchModel + { + FurnitureName = model.FurnitureName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Мебель с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/MaterialLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/MaterialLogic.cs new file mode 100644 index 0000000..05e3f09 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/MaterialLogic.cs @@ -0,0 +1,112 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class MaterialLogic : IMaterialLogic + { + private readonly ILogger _logger; + private readonly IMaterialStorage _materialStorage; + public MaterialLogic(ILogger logger, IMaterialStorage materialStorage) + { + _logger = logger; + _materialStorage = materialStorage; + } + public List? ReadList(MaterialSearchModel? model) + { + _logger.LogInformation("ReadList. MaterialName:{MaterialName}.Id:{ Id}", model?.MaterialName, model?.Id); + var list = model == null ? _materialStorage.GetFullList() : _materialStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public MaterialViewModel? ReadElement(MaterialSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. MaterialName:{MaterialName}.Id:{ Id}", model.MaterialName, model.Id); + var element = _materialStorage.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(MaterialBindingModel model) + { + CheckModel(model); + if (_materialStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(MaterialBindingModel model) + { + CheckModel(model); + if (_materialStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(MaterialBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_materialStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(MaterialBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.MaterialName)) + { + throw new ArgumentNullException("Нет названия материала", nameof(model.MaterialName)); + } + if (model.MaterialCost <= 0) + { + throw new ArgumentNullException("Цена материала должна быть больше 0", nameof(model.MaterialCost)); + } + _logger.LogInformation("Material. MaterialName:{MaterialName}.MaterialCost:{ MaterialCost}.Id: { Id}", model.MaterialName, model.MaterialCost, model.Id); + var element = _materialStorage.GetElement(new MaterialSearchModel + { + MaterialName = model.MaterialName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Материал с таким названием уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/OrderLogic.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..c22770b --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,141 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.StorageContracts; +using FurnitureFactoryContracts.ViewModels; +using FurnitureFactoryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. DateFrom:{DateFrom}. DateTo:{DateTo}. Id:{Id}", model.DateFrom, model.DateTo, 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 List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. 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 bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.OStatus != OrderStatus.Неизвестен && model.PStatus != PaymentStatus.Неизвестно) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.OStatus = OrderStatus.Принят; model.PStatus = PaymentStatus.Неоплачен; + if (_orderStorage.Insert(model) == null) + { + model.OStatus = OrderStatus.Неизвестен; + model.PStatus = PaymentStatus.Неизвестно; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + private bool StatusUpdate(OrderBindingModel model, OrderStatus newStatusO, PaymentStatus newStatusP) + { + var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (viewModel == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (viewModel.OStatus + 1 != newStatusO && viewModel.PStatus + 1 != newStatusP) + { + _logger.LogWarning("Change status operation failed"); + throw new InvalidOperationException(); + } + model.OStatus = newStatusO; + model.PStatus = newStatusP; + if (model.OStatus == OrderStatus.Готов && model.PStatus == PaymentStatus.Частично) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = viewModel.DateImplement; + } + if (viewModel.EmployeeId.HasValue) + { + model.EmployeeId = viewModel.EmployeeId.Value; + } + CheckModel(model, false); + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + public bool TakeOrderInWork(OrderBindingModel model) + { + return StatusUpdate(model, OrderStatus.Выполняется, PaymentStatus.Частично); + } + public bool FinishOrder(OrderBindingModel model) + { + model.DateImplement = DateTime.Now; + return StatusUpdate(model, OrderStatus.Готов, PaymentStatus.Оплачен); + } + public bool DeliveryOrder(OrderBindingModel model) + { + + return StatusUpdate(model, OrderStatus.Выдан, PaymentStatus.Оплачен); + } + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.OrderPrice <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.OrderPrice)); + } + _logger.LogInformation("Order. Id: {Id}. OrderPrice: {OrderPrice}. FurnitureId: {FurnitureId}", model.Id, model.OrderPrice, model.FurnitureId); + var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); + if (element != null && element.Id == model.Id) + { + throw new InvalidOperationException("Заказ с таким номером уже есть"); + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs new file mode 100644 index 0000000..17b5d8e --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/BusinessLogics/WorkModelingEmployee.cs @@ -0,0 +1,138 @@ +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.BusinessLogicsContracts; +using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; +using FurnitureFactoryDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureFactoryBusinessLogic.BusinessLogics +{ + public class WorkModelingEmployee : IWorkEmployeeImitationProcess + { + private readonly ILogger _logger; + + private readonly Random _rnd; + + private IOrderLogic? _orderLogic; + + public WorkModelingEmployee(ILogger logger) + { + _logger = logger; + _rnd = new Random(1000); + } + + public void DoWork(IEmployeeLogic employeeLogic, IOrderLogic orderLogic) + { + _orderLogic = orderLogic; + var employees = employeeLogic.ReadList(null); + if (employees == null) + { + _logger.LogWarning("DoWork. Employees is null"); + return; + } + + var orders = _orderLogic.ReadList(new OrderSearchModel { OStatuses = new() { OrderStatus.Принят, OrderStatus.Выполняется } }); + if (orders == null || orders.Count == 0) + { + _logger.LogWarning("DoWork. Orders is null or empty"); + return; + } + _logger.LogDebug("DoWork for {Count} orders", orders.Count); + foreach (var employee in employees) + { + Task.Run(() => WorkerWorkAsync(employee, orders)); + } + } + + + private async Task WorkerWorkAsync(EmployeeViewModel employee, List orders) + { + if (_orderLogic == null || employee == null) + { + return; + } + await RunOrderInWork(employee, orders); + + await Task.Run(() => + { + foreach (var order in orders) + { + try + { + _logger.LogDebug("DoWork. Worker {Id} try get order {Order}", employee.Id, order.Id); + + _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = order.Id, + EmployeeId = employee.Id + }); + + Thread.Sleep(employee.WorkExperience * _rnd.Next(100, 1000) * order.FurnitureCount); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", employee.Id, order.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = order.Id + }); + + Thread.Sleep(employee.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + }); + } + + private async Task RunOrderInWork(EmployeeViewModel employee, List allOrders) + { + if (_orderLogic == null || employee == null || allOrders == null || allOrders.Count == 0) + { + return; + } + try + { + + var runOrder = await Task.Run(() => allOrders.FirstOrDefault(x => x.EmployeeId == employee.Id && x.OStatus == OrderStatus.Выполняется)); + if (runOrder == null) + { + return; + } + + _logger.LogDebug("DoWork. Worker {Id} back to order {Order}", employee.Id, runOrder.Id); + + Thread.Sleep(employee.WorkExperience * _rnd.Next(100, 300) * runOrder.FurnitureCount); + _logger.LogDebug("DoWork. Worker {Id} finish order {Order}", employee.Id, runOrder.Id); + _orderLogic.FinishOrder(new OrderBindingModel + { + Id = runOrder.Id + }); + + Thread.Sleep(employee.Qualification * _rnd.Next(10, 100)); + } + + catch (InvalidOperationException ex) + { + _logger.LogWarning(ex, "Error try get work"); + } + + catch (Exception ex) + { + _logger.LogError(ex, "Error while do work"); + throw; + } + } + } +} diff --git a/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj new file mode 100644 index 0000000..89611d4 --- /dev/null +++ b/FurnitureFactory/FurnitureFactoryBusinessLogic/FurnitureFactoryBusinessLogic.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs index 52dab59..09a4faf 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/EmployeeBindingModel.cs @@ -13,6 +13,8 @@ namespace FurnitureFactoryContracts.BindingModels public string EmployeeFIO { get; set; } = string.Empty; public string Email { get; set; } = string.Empty; public string Password { get; set; } = string.Empty; + public int WorkExperience { get; set; } + public int Qualification { get; set; } } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/MaterialBindingModel.cs b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/MaterialBindingModel.cs index 9197a3d..57d1b29 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/MaterialBindingModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/MaterialBindingModel.cs @@ -10,7 +10,7 @@ namespace FurnitureFactoryContracts.BindingModels public class MaterialBindingModel : IMaterialModel { public int Id { get; set; } - public string MaretialName { get; set; } = string.Empty; + public string MaterialName { get; set; } = string.Empty; public double MaterialCost { get; set; } } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/OrderBindingModel.cs b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/OrderBindingModel.cs index 06521c0..d09899d 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BindingModels/OrderBindingModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BindingModels/OrderBindingModel.cs @@ -17,7 +17,7 @@ namespace FurnitureFactoryContracts.BindingModels public int FurnitureCount { get; set; } public double OrderPrice { get; set; } public OrderStatus OStatus { get; set; } = OrderStatus.Неизвестен; - public PaymentStatus PStatus { get; set; } = PaymentStatus.Неоплачен; + public PaymentStatus PStatus { get; set; } = PaymentStatus.Неизвестно; public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime? DateImplement { get; set; } public Dictionary OrderFurnitures { get; set; } = new(); diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IClientLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IClientLogic.cs index 9dff977..0d8ef18 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IClientLogic.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IClientLogic.cs @@ -1,5 +1,6 @@ using FurnitureFactoryContracts.BindingModels; using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IEmployeeLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IEmployeeLogic.cs index 493a4c1..8b1f7cd 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IEmployeeLogic.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IEmployeeLogic.cs @@ -1,5 +1,6 @@ using FurnitureFactoryContracts.BindingModels; using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IFurnitureLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IFurnitureLogic.cs index 37b9808..fa31e7a 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IFurnitureLogic.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IFurnitureLogic.cs @@ -1,5 +1,6 @@ using FurnitureFactoryContracts.BindingModels; using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IMaterialLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IMaterialLogic.cs index f983ade..0d9a342 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IMaterialLogic.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IMaterialLogic.cs @@ -1,5 +1,6 @@ using FurnitureFactoryContracts.BindingModels; using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs index b8f3f6d..90bef67 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,5 +1,6 @@ using FurnitureFactoryContracts.BindingModels; using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; diff --git a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IEmployeeStorage.cs b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IEmployeeStorage.cs index dff0b84..b3cdf81 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IEmployeeStorage.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IEmployeeStorage.cs @@ -1,4 +1,5 @@ -using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.SearchModels; using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; @@ -16,10 +17,10 @@ namespace FurnitureFactoryContracts.StorageContracts EmployeeViewModel? GetElement(EmployeeSearchModel model); - EmployeeViewModel? Insert(EmployeeSearchModel model); + EmployeeViewModel? Insert(EmployeeBindingModel model); - EmployeeViewModel? Update(EmployeeSearchModel model); + EmployeeViewModel? Update(EmployeeBindingModel model); - EmployeeViewModel? Delete(EmployeeSearchModel model); + EmployeeViewModel? Delete(EmployeeBindingModel model); } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IFurnitureStorage.cs b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IFurnitureStorage.cs index 1cb0fe7..9cd5b05 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IFurnitureStorage.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IFurnitureStorage.cs @@ -1,4 +1,5 @@ -using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.SearchModels; using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; @@ -13,8 +14,8 @@ namespace FurnitureFactoryContracts.StorageContracts List GetFullList(); List GetFilteredList(FurnitureSearchModel model); FurnitureViewModel? GetElement(FurnitureSearchModel model); - FurnitureViewModel? Insert(FurnitureSearchModel model); - FurnitureViewModel? Update(FurnitureSearchModel model); - FurnitureViewModel? Delete(FurnitureSearchModel model); + FurnitureViewModel? Insert(FurnitureBindingModel model); + FurnitureViewModel? Update(FurnitureBindingModel model); + FurnitureViewModel? Delete(FurnitureBindingModel model); } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IMaterialStorage.cs b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IMaterialStorage.cs index 46d4d7b..24c0a7c 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IMaterialStorage.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/StorageContracts/IMaterialStorage.cs @@ -1,4 +1,5 @@ -using FurnitureFactoryContracts.SearchModels; +using FurnitureFactoryContracts.BindingModels; +using FurnitureFactoryContracts.SearchModels; using FurnitureFactoryContracts.ViewModels; using System; using System.Collections.Generic; @@ -13,8 +14,8 @@ namespace FurnitureFactoryContracts.StorageContracts List GetFullList(); List GetFilteredList(MaterialSearchModel model); MaterialViewModel? GetElement(MaterialSearchModel model); - MaterialViewModel? Insert(MaterialSearchModel model); - MaterialViewModel? Update(MaterialSearchModel model); - MaterialViewModel? Delete(MaterialSearchModel model); + MaterialViewModel? Insert(MaterialBindingModel model); + MaterialViewModel? Update(MaterialBindingModel model); + MaterialViewModel? Delete(MaterialBindingModel model); } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs index 204bb4c..3999e73 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/EmployeeViewModel.cs @@ -19,5 +19,10 @@ namespace FurnitureFactoryContracts.ViewModels public string Email { get; set; } = string.Empty; [DisplayName("Пароль")] public string Password { get; set; } = string.Empty; + [DisplayName("Стаж работы")] + public int WorkExperience { get; set; } + + [DisplayName("Квалификация")] + public int Qualification { get; set; } } } diff --git a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/OrderViewModel.cs b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/OrderViewModel.cs index d08baf6..88b947f 100644 --- a/FurnitureFactory/FurnitureFactoryContracts/ViewModels/OrderViewModel.cs +++ b/FurnitureFactory/FurnitureFactoryContracts/ViewModels/OrderViewModel.cs @@ -29,7 +29,7 @@ namespace FurnitureFactoryContracts.ViewModels [DisplayName("Статус заказа")] public OrderStatus OStatus { get; set; } = OrderStatus.Неизвестен; [DisplayName("Статус оплаты")] - public PaymentStatus PStatus { get; set; } = PaymentStatus.Неоплачен; + public PaymentStatus PStatus { get; set; } = PaymentStatus.Неизвестно; [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; [DisplayName("Дата выполнения")] diff --git a/FurnitureFactory/FurnitureFactoryDataModels/Enums/PaymentStatus.cs b/FurnitureFactory/FurnitureFactoryDataModels/Enums/PaymentStatus.cs index f9a1884..579588b 100644 --- a/FurnitureFactory/FurnitureFactoryDataModels/Enums/PaymentStatus.cs +++ b/FurnitureFactory/FurnitureFactoryDataModels/Enums/PaymentStatus.cs @@ -8,8 +8,9 @@ namespace FurnitureFactoryDataModels.Enums { public enum PaymentStatus { - Неоплачен = -1, - Частично = 0, - Оплачен = 1 + Неизвестно = -1, + Неоплачен = 0, + Частично = 1, + Оплачен = 2 } } diff --git a/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs b/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs index 12fea44..426229f 100644 --- a/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs +++ b/FurnitureFactory/FurnitureFactoryDataModels/Models/IEmployeeModel.cs @@ -11,5 +11,7 @@ namespace FurnitureFactoryDataModels.Models string EmployeeFIO { get; } string Email { get; } string Password { get; } + int WorkExperience { get; } + int Qualification { get; } } }