From 341de52e3d8c16b5fd3dff2fa21b3ce7334e243f Mon Sep 17 00:00:00 2001 From: Daniel Date: Sat, 8 Apr 2023 18:52:45 +0400 Subject: [PATCH] Business Logic --- .../BusinessLogics/ComponentLogic.cs | 103 ++++++++++++ .../BusinessLogics/EngenierLogic.cs | 123 ++++++++++++++ .../BusinessLogics/LatheBusyLogic.cs | 99 ++++++++++++ .../BusinessLogics/LatheLogic.cs | 103 ++++++++++++ .../BusinessLogics/MasterLogic.cs | 150 ++++++++++++++++++ .../BusinessLogics/PlanLogic.cs | 103 ++++++++++++ .../BusinessLogics/ReinforcedLogic.cs | 107 +++++++++++++ .../BusinessLogics/ReportLogic.cs | 69 ++++++++ .../BusinessLogics/StageLogic.cs | 99 ++++++++++++ 9 files changed, 956 insertions(+) create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/ComponentLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/EngenierLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/LatheBusyLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/LatheLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/MasterLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/PlanLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/ReinforcedLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/ReportLogic.cs create mode 100644 FactoryView/FactoryBusinessLogic/BusinessLogics/StageLogic.cs diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/ComponentLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/ComponentLogic.cs new file mode 100644 index 0000000..1472fc7 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -0,0 +1,103 @@ +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryContracts.SearchModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{ Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Id: { Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/EngenierLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/EngenierLogic.cs new file mode 100644 index 0000000..e3173f5 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/EngenierLogic.cs @@ -0,0 +1,123 @@ +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class EngenierLogic : IEngenierLogic + { + private readonly ILogger _logger; + private readonly IEngenierStorage _engenierStorage; + + public EngenierLogic(ILogger logger, IEngenierStorage engenierStorage) { + _logger = logger; + _engenierStorage = engenierStorage; + } + + public bool Create(EngenierBindingModel model) + { + CheckModel(model); + if (_engenierStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(EngenierBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_engenierStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public EngenierViewModel? ReadElement(EngenierSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}.Surname:{Surname}.Patronymic:{Patronymic}.Id:{ Id}", model.Name, model.Surname, model.Patronymic, model.Id); + var element = _engenierStorage.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(EngenierSearchModel? model) + { + _logger.LogInformation("ReadList. EngenierId:{Id}", model?.Id); + var list = model == null ? _engenierStorage.GetFullList() : _engenierStorage.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(EngenierBindingModel model) + { + CheckModel(model); + if (_engenierStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + private void CheckModel(EngenierBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Fio)) + { + throw new ArgumentNullException("Нет имени пользователя", nameof(model.Fio)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет почты пользователя", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля пользователя", nameof(model.Password)); + } + _logger.LogInformation("Engenier. Name:{Fio}.Email:{Email}.Password:{Password}.Id:{Id}", + model.Fio, model.Email, model.Password, model.Id); + var element = _engenierStorage.GetElement(new EngenierSearchModel + { + Name = model.Fio, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с таким именем уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheBusyLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheBusyLogic.cs new file mode 100644 index 0000000..15623b4 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheBusyLogic.cs @@ -0,0 +1,99 @@ +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryContracts.SearchModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class LatheBusyLogic : ILatheBusyLogic + { + private readonly ILogger _logger; + private readonly ILatheBusyStorage _latheBusyStorage; + public LatheBusyLogic(ILogger logger, ILatheBusyStorage latheBusyStorage) + { + _logger = logger; + _latheBusyStorage = latheBusyStorage; + } + public List? ReadList(LatheBusySearchModel? model) + { + _logger.LogInformation("ReadList. Percent:{ComponentName}.Id:{ Id}", model?.Percent, model?.Id); + var list = model == null ? _latheBusyStorage.GetFullList() : _latheBusyStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public LatheBusyViewModel? ReadElement(LatheBusySearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{Percent}.Id:{ Id}", model.Percent, model.Id); + var element = _latheBusyStorage.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(LatheBusyBindingModel model) + { + CheckModel(model); + if (_latheBusyStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(LatheBusyBindingModel model) + { + CheckModel(model); + if (_latheBusyStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(LatheBusyBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_latheBusyStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(LatheBusyBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Id: { Id}", model.Percent, model.Id); + var element = _latheBusyStorage.GetElement(new LatheBusySearchModel + { + Percent = model.Percent + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheLogic.cs new file mode 100644 index 0000000..0f9d113 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/LatheLogic.cs @@ -0,0 +1,103 @@ +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryContracts.SearchModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class LatheLogic : ILatheLogic + { + private readonly ILogger _logger; + private readonly ILatheStorage _latheStorage; + public LatheLogic(ILogger logger, ILatheStorage latheStorage) + { + _logger = logger; + _latheStorage = latheStorage; + } + public List? ReadList(LatheSearchModel? model) + { + _logger.LogInformation("ReadList. LatheName:{LatheName}.Id:{ Id}", model?.LatheName, model?.Id); + var list = model == null ? _latheStorage.GetFullList() : _latheStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public LatheViewModel? ReadElement(LatheSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{LatheName}.Id:{ Id}", model.LatheName, model.Id); + var element = _latheStorage.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(LatheBindingModel model) + { + CheckModel(model); + if (_latheStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(LatheBindingModel model) + { + CheckModel(model); + if (_latheStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(LatheBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_latheStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(LatheBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.LatheName)) + { + throw new ArgumentNullException("Нет названия cтанка", nameof(model.LatheName)); + } + _logger.LogInformation("Component. ComponentName:{LatheName}.Id: { Id}", model.LatheName, model.Id); + var element = _latheStorage.GetElement(new LatheSearchModel + { + LatheName = model.LatheName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/MasterLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/MasterLogic.cs new file mode 100644 index 0000000..bb6060b --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/MasterLogic.cs @@ -0,0 +1,150 @@ +using FactoryContracts.BindingModels; +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class MasterLogic : IMasterLogic + { + private readonly ILogger _logger; + + private readonly IMasterStorage _masterStorage; + + public MasterLogic(ILogger logger, IMasterStorage masterStorage) + { + _logger = logger; + _masterStorage = masterStorage; + } + + public MasterViewModel? ReadElement(MasterSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation("ReadElement. MasterName:{Name}. MasterSurname:{Surname}. MasterPatronymic:{Patronymic}. Id:{Id}", + model.Name, model.Surname, model.Patronymic, model?.Id); + + var element = _masterStorage.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(MasterSearchModel? model) + { + _logger.LogInformation("ReadList. MasterName:{Name}. MasterSurname:{Surname}. MasterPatronymic:{Patronymic}. Id:{Id}", + model.Name, model.Surname, model.Patronymic, model?.Id); + + var list = model == null ? _masterStorage.GetFullList() : _masterStorage.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(MasterBindingModel model) + { + CheckModel(model); + + if (_masterStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + + return false; + } + + return true; + } + + public bool Update(MasterBindingModel model) + { + CheckModel(model); + + if (_masterStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + public bool Delete(MasterBindingModel model) + { + CheckModel(model, false); + + _logger.LogInformation("Delete. Id:{Id}", model.Id); + + if (_masterStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + + return false; + } + + return true; + } + + private void CheckModel(MasterBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Fio)) + { + throw new ArgumentNullException("Отсутствие имени в учётной записи", nameof(model.Fio)); + } + + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Отсутствие почты в учётной записи (логина)", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Отсутствие пароля в учётной записи", nameof(model.Password)); + } + + _logger.LogInformation("Master. MasterName:{Fio}.Email:{Email}.Password:{Password}.Id:{Id}", + model.Fio, model.Email, model.Password, model.Id); + var element = _masterStorage.GetElement(new MasterSearchModel + { + Email = model.Email, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Аккаунт с таким логином уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/PlanLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/PlanLogic.cs new file mode 100644 index 0000000..1f62b10 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/PlanLogic.cs @@ -0,0 +1,103 @@ +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryContracts.SearchModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class PlanLogic : IPlanLogic + { + private readonly ILogger _logger; + private readonly IPlanStorage _planStorage; + public PlanLogic(ILogger logger, IPlanStorage planStorage) + { + _logger = logger; + _planStorage = planStorage; + } + public List? ReadList(PlanSearchModel? model) + { + _logger.LogInformation("ReadList. PlanName:{PlanName}.Id:{ Id}", model?.PlanName, model?.Id); + var list = model == null ? _planStorage.GetFullList() : _planStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public PlanViewModel? ReadElement(PlanSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{PlanName}.Id:{ Id}", model.PlanName, model.Id); + var element = _planStorage.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(PlanBindingModel model) + { + CheckModel(model); + if (_planStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(PlanBindingModel model) + { + CheckModel(model); + if (_planStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(PlanBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_planStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(PlanBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PlanName)) + { + throw new ArgumentNullException("Нет названия плана", nameof(model.PlanName)); + } + _logger.LogInformation("Component. PlanName:{PlanName}.Id: { Id}", model.PlanName, model.Id); + var element = _planStorage.GetElement(new PlanSearchModel + { + PlanName = model.PlanName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/ReinforcedLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/ReinforcedLogic.cs new file mode 100644 index 0000000..785f0cc --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/ReinforcedLogic.cs @@ -0,0 +1,107 @@ +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class ReinforcedLogic : IReinforcedLogic + { + private readonly ILogger _logger; + private readonly IReinforcedStorage _reinforcedStorage; + public ReinforcedLogic(ILogger logger, IReinforcedStorage reinforcedStorage) + { + _logger = logger; + _reinforcedStorage= reinforcedStorage; + } + public List? ReadList(ReinforcedSearchModel? model) + { + _logger.LogInformation("ReadList. ReinforcedName:{ReinforcedName}.Id:{ Id}", model?.ReinforcedName, model?.Id); + var list = model == null ? _reinforcedStorage.GetFullList() : _reinforcedStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public ReinforcedViewModel? ReadElement(ReinforcedSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ReinforcedName:{ReinforcedName}.Id:{ Id}", model.ReinforcedName, model.Id); + var element = _reinforcedStorage.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(ReinforcedBindingModel model) + { + CheckModel(model); + if (_reinforcedStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(ReinforcedBindingModel model) + { + CheckModel(model); + if (_reinforcedStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(ReinforcedBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_reinforcedStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(ReinforcedBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ReinforcedName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.ReinforcedName)); + } + if(model.ReinforcedComponents==null || model.ReinforcedComponents.Count == 0) + { + throw new ArgumentNullException("Перечень компонентов не может быть пустым", nameof(model.ReinforcedComponents)); + } + _logger.LogInformation("Reinforced. ReinforcedName:{ReinforcedName}.Id: { Id}", model.ReinforcedName, model.Id); + var element = _reinforcedStorage.GetElement(new ReinforcedSearchModel + { + ReinforcedName = model.ReinforcedName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/ReportLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/ReportLogic.cs new file mode 100644 index 0000000..7005594 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/ReportLogic.cs @@ -0,0 +1,69 @@ + +using FactoryContracts.BindingModels; +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.SearchModels; +using FactoryContracts.StoragesContracts; +using FactoryContracts.ViewModels; +using PrecastConcretePlantContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class ReportLogic : IReportLogic + { + private readonly IComponentStorage _componentStorage; + private readonly IPlanStorage _planStorage; + private readonly ILatheStorage _latheStorage; + private readonly ILatheBusyStorage _latheBusyStorage; + + + public ReportLogic(IComponentStorage componentStorage, IPlanStorage planStorage, ILatheStorage latheStorage, ILatheBusyStorage latheBusyStorage) + { + _planStorage = planStorage; + _componentStorage = componentStorage; + _latheStorage = latheStorage; + _latheBusyStorage = latheBusyStorage; + } + + public List GetPlanLathesAndComponents(ReportBindingModel model) + { + return _planStorage.GetFilteredList(new PlanSearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo}) + .Select(x => new ReportLatheComponentViewModel { + PlanName = x.PlanName, + Components = x.PlanComponents.Select(x => (x.Value.Item1.ComponentName, x.Value.Item2)).ToList(), + Lathes = x.PlanLathes.Select(x => (x.Value.Item1.LatheName, x.Value.Item2)).ToList() + }) + .ToList(); + } + + public List GetLatheByBusy(ReportBindingModel model) + { + return _latheBusyStorage.GetFilteredList(new LatheBusySearchModel { DateFrom = model.DateFrom, DateTo = model.DateTo }) + .Select(x => new ReportLatheViewModel + { + Lathes = _latheStorage.GetFilteredList(new LatheSearchModel { BusyId = x.Id}).Select(y => y.LatheName).ToList(), + }) + .ToList(); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveReinforcedComponentToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveReinforcedesToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/FactoryView/FactoryBusinessLogic/BusinessLogics/StageLogic.cs b/FactoryView/FactoryBusinessLogic/BusinessLogics/StageLogic.cs new file mode 100644 index 0000000..328f320 --- /dev/null +++ b/FactoryView/FactoryBusinessLogic/BusinessLogics/StageLogic.cs @@ -0,0 +1,99 @@ +using FactoryContracts.BusinessLogicsContracts; +using FactoryContracts.StoragesContracts; +using Microsoft.Extensions.Logging; +using FactoryContracts.BindingModels; +using FactoryContracts.ViewModels; +using FactoryContracts.SearchModels; + +namespace FactoryBusinessLogic.BusinessLogics +{ + public class StageLogic : IStageLogic + { + private readonly ILogger _logger; + private readonly IStageStorage _stageStorage; + public StageLogic(ILogger logger, IStageStorage stageStorage) + { + _logger = logger; + _stageStorage = stageStorage; + } + public List? ReadList(StageSearchModel? model) + { + _logger.LogInformation("ReadList. StageId:{Id}", model?.Id); + var list = model == null ? _stageStorage.GetFullList() : _stageStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + public StageViewModel? ReadElement(StageSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. StageId:{Id}", model?.Id); + var element = _stageStorage.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(StageBindingModel model) + { + CheckModel(model); + if (_stageStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + public bool Update(StageBindingModel model) + { + CheckModel(model); + if (_stageStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool Delete(StageBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_stageStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + private void CheckModel(StageBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + _logger.LogInformation("Stage.Id:{Id}", model?.Id); + var element = _stageStorage.GetElement(new StageSearchModel + { + Id = model.Id + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +}