From 2b16a3c314d6bac593c38101721994a9989fbc0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=BE=D1=84=D1=8C=D1=8F=20=D0=AF=D0=BA=D0=BE=D0=B1?= =?UTF-8?q?=D1=87=D1=83=D0=BA?= Date: Wed, 1 May 2024 01:59:04 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81=20=D0=BB?= =?UTF-8?q?=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=BD=D0=B8=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/CaseLogic.cs | 190 ++++++++++++++++++ .../BusinessLogics/ClientLogic.cs | 153 ++++++++++++++ .../BusinessLogics/ExecutorLogic.cs | 126 ++++++++++++ .../BusinessLogics/VisitLogic.cs | 139 +++++++++++++ .../LawCompanyBusinessLogic.csproj | 26 +-- .../LawCompanyDatabaseImplement.csproj | 2 + 6 files changed, 623 insertions(+), 13 deletions(-) create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs create mode 100644 LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs new file mode 100644 index 0000000..4ba768d --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/CaseLogic.cs @@ -0,0 +1,190 @@ +using LawCompanyDataModels.Enums; +using LawCompanyDataModels.Models; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawCompanyBusinessLogic.BusinessLogics +{ + public class CaseLogic : ICaseLogic + { + private readonly ILogger _logger; + private readonly ICaseStorage _caseStorage; + + public CaseLogic(ILogger logger, ICaseStorage CaseStorage) + { + _logger = logger; + _caseStorage = CaseStorage; + } + + public bool CaseAnalysis(CaseBindingModel model) + { + return UpdateStatus(model, CaseStatus.АнализДелаИПодготовкаДокументов); + } + + public bool CaseHearing(CaseBindingModel model) + { + return UpdateStatus(model, CaseStatus.СлушанияДела); + } + + public bool CloseCase(CaseBindingModel model) + { + return UpdateStatus(model, CaseStatus.ЗакрытиеДела); + } + + public bool CreateCase(CaseBindingModel model) + { + CheckModel(model); + + if (model.Status != CaseStatus.Неизвестен) + { + _logger.LogWarning("Case status is incorrect"); + return false; + } + + model.Status = CaseStatus.Принято; + model.DateCreate = DateTime.Now; + + if (_caseStorage.Insert(model) == null) + { + model.Status = CaseStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool DeleteCase(CaseBindingModel model) + { + if (_caseStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public CaseViewModel? ReadElement(CaseSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Name:{Name}. Id:{Id}", model.Name, model.Id); + var element = _caseStorage.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 Update(CaseBindingModel model) + { + CheckModel(model); + if (_caseStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public List? ReadList(CaseSearchModel? model) + { + _logger.LogInformation("ReadList. CaseId:{Id}", model?.Id); + var list = model == null ? _caseStorage.GetFullList() : _caseStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool AddClientToCase(CaseSearchModel model, IClientModel client) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + _logger.LogInformation(" CaseName:{CaseName}.Id:{Id}", model.Name, model.Id); + var element = _caseStorage.GetElement(model); + + if (element == null) + { + + return false; + } + if (element.CaseClients.ContainsKey(client.Id)) + { + return false; + } + element.CaseClients[client.Id] = client; + + _caseStorage.Update(new() + { + Id = element.Id, + Name = element.Name, + DateCreate = element.DateCreate, + Status = element.Status, + CaseClients = element.CaseClients + }); + + return true; + } + private void CheckModel(CaseBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + if (!withParams) + { + return; + } + + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет описания дела", nameof(model.Name)); + + } + + _logger.LogInformation("Case. CaseID:{Id}, Name:{Name}.", model.Id, model.Name); + } + private bool UpdateStatus(CaseBindingModel model, CaseStatus newStatus) + { + CheckModel(model); + if (model.Status + 1 != newStatus) + { + + _logger.LogWarning("Status incorrected"); + return false; + + } + model.Status = newStatus; + if (model.Status == CaseStatus.ЗакрытиеДела) + { + model.DateImplement = DateTime.Now; + } + if (_caseStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Update operation failed"); + + return false; + } + + return true; + } + + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..202ba3b --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,153 @@ +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawCompanyBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + + public ClientLogic(ILogger logger, IClientStorage ClientStorage) + { + _logger = logger; + _clientStorage = ClientStorage; + } + + public bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + _logger.LogWarning("Insert 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; + } + + public List? ReadCaseElementList(CaseSearchModel? model) + { + if (model == null) + { + return null; + } + var list = _clientStorage.GetClientCaseList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public List? ReadVisitElementList(VisitSearchModel? model) + { + if (model == null) + { + return null; + } + var list = _clientStorage.GetClientVisitList(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. ClientName:{FIO}. Id:{Id}", model.FIO, 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 List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. ClientName:{ClientName}.Id:{Id}", model?.FIO, 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 bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + _logger.LogWarning("Update 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.FIO)) + { + throw new ArgumentNullException("Нет имени клиента", nameof(model.FIO)); + } + if (string.IsNullOrEmpty(model.Email)) + { + throw new ArgumentNullException("Нет e-mail клиента", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет телефона клиента", nameof(model.Phone)); + } + + _logger.LogInformation("Client. ClientName:{FIO}. E-mail:{Email}. Phone: {Phone} Id: {Id} ", model.FIO, model.Email, model.Phone, model.Id); + var element = _clientStorage.GetElement(new ClientSearchModel + { + FIO = model.FIO, + Phone = model.Phone, + Email = model.Email + + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с такими данными уже есть"); + } + } + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs new file mode 100644 index 0000000..b7491cc --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/ExecutorLogic.cs @@ -0,0 +1,126 @@ +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LawCompanyBusinessLogic.BusinessLogics +{ + public class ExecutorLogic : IExecutorLogic + { + private readonly ILogger _logger; + private readonly IExecutorStorage _executorStorage; + + public ExecutorLogic(ILogger logger, IExecutorStorage executorStorage) + { + _logger = logger; + _executorStorage = executorStorage; + } + + public bool Create(ExecutorBindingModel model) + { + CheckModel(model); + if (_executorStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ExecutorBindingModel model) + { + CheckModel(model); + if (_executorStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ExecutorBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_executorStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public List? ReadList(ExecutorSearchModel? model) + { + _logger.LogInformation("ReadList. ExecutorName:{ExecutorName}.Id:{Id}", model?.FIO, model?.Id); + var list = model == null ? _executorStorage.GetFullList() : _executorStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ExecutorViewModel? ReadElement(ExecutorSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ExecutorName:{ExecutorName}. Id:{Id}", model.FIO, model.Id); + var element = _executorStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + private void CheckModel(ExecutorBindingModel 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("Нет e-mail исполнителя", nameof(model.Email)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля исполнителя", nameof(model.Password)); + } + + _logger.LogInformation("Executor. ExecutorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id); + var element = _executorStorage.GetElement(new ExecutorSearchModel + { + FIO = model.FIO, + Email = model.Email, + Password = model.Password, + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Клиент с такими данными уже есть"); + } + } + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs new file mode 100644 index 0000000..c52b0eb --- /dev/null +++ b/LawCompany/LawCompanyBusinessLogic/BusinessLogics/VisitLogic.cs @@ -0,0 +1,139 @@ +using LawCompanyDataModels.Models; +using LawCompanyContracts.BindingModels; +using LawCompanyContracts.BusinessLogicContracts; +using LawCompanyContracts.SearchModels; +using LawCompanyContracts.StoragesContracts; +using LawCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace LawCompanyBusinessLogic.BusinessLogics +{ + public class VisitLogic : IVisitLogic + { + private readonly ILogger _logger; + private readonly IVisitStorage _visitStorage; + + public VisitLogic(ILogger logger, IVisitStorage VisitStorage) + { + _logger = logger; + _visitStorage = VisitStorage; + } + + public bool Create(VisitBindingModel model) + { + CheckModel(model); + if (_visitStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Delete(VisitBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_visitStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public VisitViewModel? ReadElement(VisitSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. VisitDate:{VisitDate}. Id:{Id}", model.VisitDate, model.Id); + var element = _visitStorage.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(VisitSearchModel? model) + { + _logger.LogInformation("ReadList. VisitDate:{VisitDate}.Id:{Id}", model?.VisitDate, model?.Id); + var list = model == null ? _visitStorage.GetFullList() : _visitStorage.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(VisitBindingModel model) + { + CheckModel(model); + if (_visitStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + public bool AddClientToVisit(VisitSearchModel model, IClientModel client) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + + var element = _visitStorage.GetElement(model); + + if (element == null) + { + return false; + } + + element.VisitClients[client.Id] = client; + + _visitStorage.Update(new() + { + Id = element.Id, + VisitDate = element.VisitDate, + HearingId = element.HearingId, + VisitClients = element.VisitClients + }); + + return true; + } + private void CheckModel(VisitBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty((model.VisitDate).ToString())) + { + throw new ArgumentNullException("Не поставлено время", nameof(model.VisitDate)); + } + + _logger.LogInformation("Visit. VisitDate:{VisitDate}. Id: {Id} ", model.VisitDate, model.Id); + var element = _visitStorage.GetElement(new VisitSearchModel + { + VisitDate = model.VisitDate + + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("На данное время уже назначен визит"); + } + } + } +} diff --git a/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj b/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj index 557ae76..7cd0327 100644 --- a/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj +++ b/LawCompany/LawCompanyBusinessLogic/LawCompanyBusinessLogic.csproj @@ -1,18 +1,18 @@ - - net6.0 - enable - enable - + + net6.0 + enable + enable + - - - - - - - - + + + + + + + + diff --git a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabaseImplement.csproj b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabaseImplement.csproj index d1b180c..9bc9313 100644 --- a/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabaseImplement.csproj +++ b/LawCompany/LawCompanyDatabaseImplement/LawCompanyDatabaseImplement.csproj @@ -9,6 +9,8 @@ + +