правки
This commit is contained in:
parent
9c4ea547f1
commit
65decf8f3f
@ -1,139 +1,146 @@
|
||||
using LawCompanyContracts.BindingModels;
|
||||
using LawCompanyDataModels.Models;
|
||||
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 class HearingLogic : IHearingLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IHearingStorage _hearingStorage;
|
||||
|
||||
public HearingLogic(ILogger<HearingLogic> logger, IHearingStorage hearingStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_hearingStorage = 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 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 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 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 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));
|
||||
}
|
||||
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);
|
||||
var element = _hearingStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (element == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (element.HearingLawyers.ContainsKey(lawyer.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
element.HearingLawyers[lawyer.Id] = lawyer;
|
||||
|
||||
element.HearingLawyers[lawyer.Id] = lawyer;
|
||||
_hearingStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
HearingDate = element.HearingDate,
|
||||
Judge = element.Judge,
|
||||
HearingLawyers = element.HearingLawyers,
|
||||
GuarantorId = element.GuarantorId,
|
||||
});
|
||||
|
||||
_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.Judge))
|
||||
{
|
||||
throw new ArgumentNullException("Не указан суд",
|
||||
nameof(model.Judge));
|
||||
}
|
||||
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
|
||||
|
||||
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("На данное время уже назначено слушание");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("На данное время уже назначено слушание");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -2,12 +2,12 @@
|
||||
|
||||
namespace LawCompanyContracts.BindingModels
|
||||
{
|
||||
public class HearingBindingModel : IHearingModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime HearingDate { get; set; }
|
||||
public string Judge { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||
}
|
||||
public class HearingBindingModel : IHearingModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime HearingDate { get; set; }
|
||||
public string Judge { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,6 @@ namespace LawCompanyContracts.BindingModels
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public int? GuarantorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -3,17 +3,15 @@ using System.ComponentModel;
|
||||
|
||||
namespace LawCompanyContracts.ViewModels
|
||||
{
|
||||
public class HearingViewModel : IHearingModel
|
||||
{
|
||||
[DisplayName("Номер слушания")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Дата слушания")]
|
||||
public DateTime HearingDate { get; set; }
|
||||
[DisplayName("Суд")]
|
||||
public string Judge { get; set; } = string.Empty;
|
||||
[DisplayName("Имя поручителя")]
|
||||
public string GuarantorName { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||
}
|
||||
public class HearingViewModel : IHearingModel
|
||||
{
|
||||
[DisplayName("Номер слушания")]
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Дата слушания")]
|
||||
public DateTime HearingDate { get; set; }
|
||||
[DisplayName("Суд")]
|
||||
public string Judge { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||
}
|
||||
}
|
@ -13,6 +13,6 @@ namespace LawCompanyContracts.ViewModels
|
||||
public string Phone { get; set; } = string.Empty;
|
||||
[DisplayName("E-mail юриста")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public int GuarantorId { get; set; }
|
||||
public int? GuarantorId { get; set; }
|
||||
}
|
||||
}
|
@ -11,6 +11,6 @@ namespace LawCompanyDataModels.Models
|
||||
string FIO { get; }
|
||||
string Phone { get; }
|
||||
string Email { get; }
|
||||
public int GuarantorId { get; }
|
||||
public int? GuarantorId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,71 @@
|
||||
using LawCompanyContracts.BindingModels;
|
||||
using LawCompanyDataModels.Models;
|
||||
using LawCompanyContracts.BindingModels;
|
||||
using LawCompanyContracts.ViewModels;
|
||||
using LawCompanyDatabaseImplement.Models;
|
||||
using LawCompanyDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using LawFirmDatabaseImplement.Models;
|
||||
|
||||
namespace LawFirmDatabaseImplement.Models
|
||||
namespace LawCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Guarantor : IGuarantorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string FIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Hearing> Hearings { get; set; } = new();
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Lawyer> Lawyers { get; set; } = new();
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Consultation> Consultations { get; set; } = new();
|
||||
public class Guarantor : IGuarantorModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string FIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Hearing> Hearings { get; set; } = new();
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Lawyer> Lawyers { get; set; } = new();
|
||||
[ForeignKey("GuarantorId")]
|
||||
public virtual List<Consultation> Consultations { get; set; } = new();
|
||||
|
||||
public static Guarantor? Create(GuarantorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Guarantor()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public static Guarantor? Create(LawCompanyDatabase context, GuarantorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Guarantor()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
|
||||
public static Guarantor Create(GuarantorViewModel model)
|
||||
{
|
||||
return new Guarantor
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
public static Guarantor Create(GuarantorViewModel model)
|
||||
{
|
||||
return new Guarantor
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(GuarantorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
public void Update(GuarantorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public GuarantorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
}
|
||||
public GuarantorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
}
|
||||
}
|
@ -1,71 +1,72 @@
|
||||
using LawCompanyContracts.BindingModels;
|
||||
using LawCompanyDataModels.Models;
|
||||
using LawCompanyContracts.BindingModels;
|
||||
using LawCompanyContracts.ViewModels;
|
||||
using LawCompanyDatabaseImplement.Models;
|
||||
using LawCompanyDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.Design;
|
||||
|
||||
|
||||
namespace LawFirmDatabaseImplement.Models
|
||||
namespace LawCompanyDatabaseImplement.Models
|
||||
{
|
||||
public class Lawyer : ILawyerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string FIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Phone { get; private set; } = string.Empty;
|
||||
[ForeignKey("LawyerId")]
|
||||
public virtual List<HearingLawyer> HearingLawyers { get; set; } = new();
|
||||
[ForeignKey("LawyerId")]
|
||||
public virtual List<ConsultationLawyer> ConsultationLawyers { get; set; } = new();
|
||||
public int GuarantorId { get; set; }
|
||||
public class Lawyer : ILawyerModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public string FIO { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string Phone { get; private set; } = string.Empty;
|
||||
[ForeignKey("LawyerId")]
|
||||
public virtual List<HearingLawyer> HearingLawyers { get; set; } = new();
|
||||
[ForeignKey("LawyerId")]
|
||||
public virtual List<ConsultationLawyer> ConsultationLawyers { get; set; } = new();
|
||||
public int? GuarantorId { get; set; }
|
||||
|
||||
public static Lawyer? Create(LawyerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Lawyer()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Phone = model.Phone,
|
||||
GuarantorId = model.GuarantorId,
|
||||
};
|
||||
}
|
||||
public static Lawyer Create(LawyerViewModel model)
|
||||
{
|
||||
return new Lawyer
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Phone = model.Phone,
|
||||
GuarantorId = model.GuarantorId,
|
||||
};
|
||||
}
|
||||
public void Update(LawyerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Email = model.Email;
|
||||
Phone = model.Phone;
|
||||
}
|
||||
public LawyerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Email = Email,
|
||||
Phone = Phone,
|
||||
GuarantorId = GuarantorId
|
||||
};
|
||||
}
|
||||
public static Lawyer? Create(LawCompanyDatabase context, LawyerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Lawyer()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Phone = model.Phone,
|
||||
GuarantorId = model.GuarantorId,
|
||||
};
|
||||
}
|
||||
public static Lawyer Create(LawyerViewModel model)
|
||||
{
|
||||
return new Lawyer
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Email = model.Email,
|
||||
Phone = model.Phone,
|
||||
GuarantorId = model.GuarantorId,
|
||||
};
|
||||
}
|
||||
public void Update(LawyerBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FIO = model.FIO;
|
||||
Email = model.Email;
|
||||
Phone = model.Phone;
|
||||
if (!model.GuarantorId.HasValue) GuarantorId = model.GuarantorId;
|
||||
}
|
||||
public LawyerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FIO = FIO,
|
||||
Email = Email,
|
||||
Phone = Phone,
|
||||
GuarantorId = GuarantorId
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user