бизнес логика исполнителя

This commit is contained in:
Софья Якобчук 2024-05-01 01:59:04 +04:00
parent 1c2f7d5faf
commit 2b16a3c314
6 changed files with 623 additions and 13 deletions

View File

@ -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<CaseLogic> 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<CaseViewModel>? 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;
}
}
}

View File

@ -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<ClientLogic> 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<ClientViewModel>? 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<ClientViewModel>? 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<ClientViewModel>? 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("Клиент с такими данными уже есть");
}
}
}
}

View File

@ -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<ExecutorViewModel>? 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("Клиент с такими данными уже есть");
}
}
}
}

View File

@ -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<VisitLogic> 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<VisitViewModel>? 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("На данное время уже назначен визит");
}
}
}
}

View File

@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="BusinessLogics\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawFimDataModels\LawFimDataModels.csproj" />
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LawCompanyDataModels\LawCompanyDataModels.csproj" />
<ProjectReference Include="..\LawCompanyContracts\LawCompanyContracts.csproj" />
</ItemGroup>
</Project>

View File

@ -9,6 +9,8 @@
<ItemGroup>
<Folder Include="Implements\" />
<Folder Include="Models\" />
<Folder Include="Implements\" />
<Folder Include="Models\" />
</ItemGroup>
<ItemGroup>