2024-05-01 02:33:49 +04:00
|
|
|
|
using LawCompanyContracts.BindingModels;
|
|
|
|
|
using LawCompanyContracts.BusinessLogicContracts;
|
|
|
|
|
using LawCompanyContracts.SearchModels;
|
|
|
|
|
using LawCompanyContracts.StoragesContracts;
|
|
|
|
|
using LawCompanyContracts.ViewModels;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
namespace LawCompanyBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public class LawyerLogic : ILawyerLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
private readonly ILawyerStorage _lawyerStorage;
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public LawyerLogic(ILogger<LawyerLogic> logger, ILawyerStorage lawyerStorage)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_lawyerStorage = lawyerStorage;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public bool Create(LawyerBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_lawyerStorage.Insert(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Insert operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public bool Delete(LawyerBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model, false);
|
|
|
|
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
|
|
|
|
if (_lawyerStorage.Delete(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Delete operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public List<LawyerViewModel>? ReadHearingElementList(HearingSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var list = _lawyerStorage.GetLawyerHearingList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public List<LawyerViewModel>? ReadConsultationElementList(ConsultationSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
var list = _lawyerStorage.GetLawyerConsultationList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public LawyerViewModel? ReadElement(LawyerSearchModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement. LawyerName:{FIO}. Id:{Id}", model.FIO, model.Id);
|
|
|
|
|
var element = _lawyerStorage.GetElement(model);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadElement element not found");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
|
|
|
|
return element;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public List<LawyerViewModel>? ReadList(LawyerSearchModel? model)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation("ReadList. LawyerName:{LawyerName}.Id:{Id}", model?.FIO, model?.Id);
|
|
|
|
|
var list = model == null ? _lawyerStorage.GetFullList() : _lawyerStorage.GetFilteredList(model);
|
|
|
|
|
if (list == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("ReadList return null list");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
|
|
|
|
return list;
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
public bool Update(LawyerBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_lawyerStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning("Update operation failed");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
private void CheckModel(LawyerBindingModel 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.Phone))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет телефона юриста", nameof(model.Phone));
|
|
|
|
|
}
|
|
|
|
|
if (string.IsNullOrEmpty(model.Email))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет e-mail юриста", nameof(model.Email));
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
_logger.LogInformation("Lawyer. LawyerName:{FIO}. Phone: {Phone}. E-mail:{Email}. Id: {Id} ", model.FIO, model.Phone, model.Email, model.Id);
|
|
|
|
|
var element = _lawyerStorage.GetElement(new LawyerSearchModel
|
|
|
|
|
{
|
|
|
|
|
FIO = model.FIO,
|
|
|
|
|
Phone = model.Phone,
|
|
|
|
|
Email = model.Email,
|
2024-05-01 02:33:49 +04:00
|
|
|
|
|
2024-05-01 23:48:28 +04:00
|
|
|
|
});
|
|
|
|
|
if (element != null && element.Id != model.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Юрист с такими данными уже есть");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-01 02:33:49 +04:00
|
|
|
|
}
|