фиксики поручителя

This commit is contained in:
sofiaivv 2024-05-01 02:33:49 +04:00
parent 0c285ff7b6
commit 913b2ae413
9 changed files with 671 additions and 5 deletions

View File

@ -0,0 +1,140 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDataModels.Models;
using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class ConsultationLogic : IConsultationLogic
{
private readonly ILogger _logger;
private readonly IConsultationStorage _consultationStorage;
public ConsultationLogic(ILogger<ConsultationLogic> logger, IConsultationStorage consultationStorage)
{
_logger = logger;
_consultationStorage = consultationStorage;
}
public bool Create(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(ConsultationBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_consultationStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public ConsultationViewModel? ReadElement(ConsultationSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ConsultationDate:{ConsultationDate}. Id:{Id}", model.ConsultationDate, model.Id);
var element = _consultationStorage.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<ConsultationViewModel>? ReadList(ConsultationSearchModel? model)
{
_logger.LogInformation("ReadList. ConsultationDate:{ConsultationDate}.Id:{Id}", model?.ConsultationDate, model?.Id);
var list = model == null ? _consultationStorage.GetFullList() : _consultationStorage.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(ConsultationBindingModel model)
{
CheckModel(model);
if (_consultationStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool AddLawyerToConsultation(ConsultationSearchModel model, ILawyerModel lawyer)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _consultationStorage.GetElement(model);
if (element == null)
{
return false;
}
element.ConsultationLawyers[lawyer.Id] = lawyer;
_consultationStorage.Update(new()
{
Id = element.Id,
Cost = element.Cost,
ConsultationDate = element.ConsultationDate,
CaseId = element.CaseId,
ConsultationLawyers = element.ConsultationLawyers,
GuarantorId = element.GuarantorId,
});
return true;
}
private void CheckModel(ConsultationBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty((model.ConsultationDate).ToString()))
{
throw new ArgumentNullException("Не поставлено время", nameof(model.ConsultationDate));
}
_logger.LogInformation("Consultation. ConsultationDate:{ConsultationDate}. Id: {Id} ", model.ConsultationDate, model.Id);
var element = _consultationStorage.GetElement(new ConsultationSearchModel
{
ConsultationDate = model.ConsultationDate
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("На данное время уже назначена консультация");
}
}
}
}

View File

@ -119,8 +119,8 @@ namespace LawCompanyBusinessLogic.BusinessLogics
}); });
if (element != null && element.Id != model.Id) if (element != null && element.Id != model.Id)
{ {
throw new InvalidOperationException("Клиент с такими данными уже есть"); throw new InvalidOperationException("Исполнитель с такими данными уже есть");
} }
} }
} }
} }

View File

@ -0,0 +1,121 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class GuarantorLogic : IGuarantorLogic
{
private readonly ILogger _logger;
private readonly IGuarantorStorage _guarantorStorage;
public GuarantorLogic(ILogger logger, IGuarantorStorage guarantorStorage)
{
_logger = logger;
_guarantorStorage = guarantorStorage;
}
public bool Create(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(GuarantorBindingModel model)
{
CheckModel(model);
if (_guarantorStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(GuarantorBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_guarantorStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public List<GuarantorViewModel>? ReadList(GuarantorSearchModel? model)
{
_logger.LogInformation("ReadList. GuarantorName:{GuarantorName}.Id:{Id}", model?.FIO, model?.Id);
var list = model == null ? _guarantorStorage.GetFullList() : _guarantorStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public GuarantorViewModel? ReadElement(GuarantorSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. GuarantorName:{GuarantorName}. Id:{Id}", model.FIO, model.Id);
var element = _guarantorStorage.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(GuarantorBindingModel 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("Guarantor. GuarantorName:{FIO}. E-mail:{Email}. Password: {Password} Id: {Id} ", model.FIO, model.Email, model.Password, model.Id);
var element = _guarantorStorage.GetElement(new GuarantorSearchModel
{
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 LawCompanyContracts.BindingModels;
using LawCompanyContracts.BusinessLogicContracts;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDataModels.Models;
using Microsoft.Extensions.Logging;
namespace LawCompanyBusinessLogic.BusinessLogics
{
public class HearingLogic : IHearingLogic
{
private readonly ILogger _logger;
private readonly IHearingStorage _hearingStorage;
public HearingLogic(ILogger<HearingLogic> logger, IHearingStorage hearingStorage)
{
_logger = logger;
_hearingStorage = hearingStorage;
}
public bool Create(HearingBindingModel model)
{
CheckModel(model);
if (_hearingStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(HearingBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_hearingStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public HearingViewModel? ReadElement(HearingSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. HearingDate:{HearingDate}. Id:{Id}", model.HearingDate, model.Id);
var element = _hearingStorage.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<HearingViewModel>? ReadList(HearingSearchModel? model)
{
_logger.LogInformation("ReadList. HearingDate:{HearingDate}.Id:{Id}", model?.HearingDate, model?.Id);
var list = model == null ? _hearingStorage.GetFullList() : _hearingStorage.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(HearingBindingModel model)
{
CheckModel(model);
if (_hearingStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel lawyer)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _hearingStorage.GetElement(model);
if (element == null)
{
return false;
}
element.HearingLawyers[lawyer.Id] = lawyer;
_hearingStorage.Update(new()
{
Id = element.Id,
HearingDate = element.HearingDate,
Judge = element.Judge,
HearingLawyers = element.HearingLawyers,
GuarantorId = element.GuarantorId,
});
return true;
}
private void CheckModel(HearingBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty((model.HearingDate).ToString()))
{
throw new ArgumentNullException("Не поставлено время", nameof(model.HearingDate));
}
_logger.LogInformation("Hearing. HearingDate:{HearingDate}. Id: {Id} ", model.HearingDate, model.Id);
var element = _hearingStorage.GetElement(new HearingSearchModel
{
HearingDate = model.HearingDate
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("На данное время уже назначено слушание");
}
}
}
}

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 LawyerLogic : ILawyerLogic
{
private readonly ILogger _logger;
private readonly ILawyerStorage _lawyerStorage;
public LawyerLogic(ILogger<LawyerLogic> logger, ILawyerStorage lawyerStorage)
{
_logger = logger;
_lawyerStorage = lawyerStorage;
}
public bool Create(LawyerBindingModel model)
{
CheckModel(model);
if (_lawyerStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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));
}
_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,
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Юрист с такими данными уже есть");
}
}
}
}

View File

@ -5,7 +5,7 @@ namespace LawCompanyContracts.BindingModels
public class ConsultationBindingModel : IConsultationModel public class ConsultationBindingModel : IConsultationModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string Cost { get; set; } public double Cost { get; set; }
public DateTime ConsultationDate { get; set; } public DateTime ConsultationDate { get; set; }
public int CaseId { get; set; } public int CaseId { get; set; }
public int GuarantorId { get; set; } public int GuarantorId { get; set; }

View File

@ -9,6 +9,8 @@ namespace LawCompanyContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Цена консультации")] [DisplayName("Цена консультации")]
public double Cost { get; set; } public double Cost { get; set; }
[DisplayName("Дата консультации")]
public DateTime ConsultationDate { get; set; }
[DisplayName("Дело")] [DisplayName("Дело")]
public string CaseName { get; set; } = string.Empty; public string CaseName { get; set; } = string.Empty;
public int CaseId { get; set; } public int CaseId { get; set; }

View File

@ -0,0 +1,111 @@
using LawCompanyContracts.BindingModels;
using LawCompanyContracts.SearchModels;
using LawCompanyContracts.StoragesContracts;
using LawCompanyContracts.ViewModels;
using LawCompanyDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace LawCompanyDatabaseImplement.Implements
{
public class ConsultationStorage : IConsultationStorage
{
public List<ConsultationViewModel> GetFullList()
{
using var context = new LawCompanyDatabase();
return context.Consultations
.Include(x => x.Lawyers)
.ThenInclude(x => x.Lawyer)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<ConsultationViewModel> GetFilteredList(ConsultationSearchModel model)
{
if (!model.Id.HasValue && !model.Cost.HasValue && !model.ConsultationDate.HasValue
&& !model.CaseId.HasValue && !model.GuarantorId.HasValue)
{
return new();
}
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
{
using var context = new LawCompanyDatabase();
return context.Consultations
.Include(x => x.Lawyers).ThenInclude(x => x.Lawyer)
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
else
{
using var context = new LawCompanyDatabase();
return context.Consultations
.Include(x => x.Lawyers).ThenInclude(x => x.Lawyer)
.Where(x => x.ConsultationDate >= model.DateFrom && x.ConsultationDate <= model.DateTo)
.Select(x => x.GetViewModel)
.ToList();
}
}
public ConsultationViewModel? GetElement(ConsultationSearchModel model)
{
if (!model.Id.HasValue && !model.ConsultationDate.HasValue && !model.CaseId.HasValue)
{
return new();
}
using var context = new LawCompanyDatabase();
return context.Consultations.Include(x => x.Lawyers).ThenInclude(x => x.Lawyer)
.FirstOrDefault(x => (model.CaseId.HasValue && x.Case == model.CaseId)
|| (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public ConsultationViewModel? Insert(ConsultationBindingModel model)
{
using var context = new LawCompanyDatabase();
var newConsultation = Consultation.Create(context, model);
if (newConsultation == null)
{
return null;
}
context.Consultations.Add(newConsultation);
context.SaveChanges();
return newConsultation.GetViewModel;
}
public ConsultationViewModel? Update(ConsultationBindingModel model)
{
using var context = new LawCompanyDatabase();
using var transaction = context.Database.BeginTransaction();
try
{
var consultation = context.Consultations.FirstOrDefault(rec =>
rec.Id == model.Id);
if (consultation == null)
{
return null;
}
consultation.Update(model);
context.SaveChanges();
consultation.UpdateLawyers(context, model);
transaction.Commit();
return consultation.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ConsultationViewModel? Delete(ConsultationBindingModel model)
{
using var context = new LawCompanyDatabase();
var element = context.Consultations
.Include(x => x.Lawyers)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Consultations.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace LawCompanyDatabaseImplement namespace LawCompanyDatabaseImplement
{ {
internal class LawFirmDatabase internal class LawCompanyDatabase
{ {
} }
} }