правки
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.BusinessLogicContracts;
|
||||||
using LawCompanyContracts.SearchModels;
|
using LawCompanyContracts.SearchModels;
|
||||||
using LawCompanyContracts.StoragesContracts;
|
using LawCompanyContracts.StoragesContracts;
|
||||||
using LawCompanyContracts.ViewModels;
|
using LawCompanyContracts.ViewModels;
|
||||||
using LawCompanyDataModels.Models;
|
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace LawCompanyBusinessLogic.BusinessLogics
|
namespace LawCompanyBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class HearingLogic : IHearingLogic
|
public class HearingLogic : IHearingLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IHearingStorage _hearingStorage;
|
private readonly IHearingStorage _hearingStorage;
|
||||||
|
|
||||||
public HearingLogic(ILogger<HearingLogic> logger, IHearingStorage hearingStorage)
|
public HearingLogic(ILogger<HearingLogic> logger, IHearingStorage hearingStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_hearingStorage = hearingStorage;
|
_hearingStorage = hearingStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(HearingBindingModel model)
|
public bool Create(HearingBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (_hearingStorage.Insert(model) == null)
|
if (_hearingStorage.Insert(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Delete(HearingBindingModel model)
|
public bool Delete(HearingBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
if (_hearingStorage.Delete(model) == null)
|
if (_hearingStorage.Delete(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HearingViewModel? ReadElement(HearingSearchModel model)
|
public HearingViewModel? ReadElement(HearingSearchModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement. HearingDate:{HearingDate}. Id:{Id}", model.HearingDate, model.Id);
|
_logger.LogInformation("ReadElement. HearingDate:{HearingDate}. Id:{Id}", model.HearingDate, model.Id);
|
||||||
var element = _hearingStorage.GetElement(model);
|
var element = _hearingStorage.GetElement(model);
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not found");
|
_logger.LogWarning("ReadElement element not found");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HearingViewModel>? ReadList(HearingSearchModel? model)
|
public List<HearingViewModel>? ReadList(HearingSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. HearingDate:{HearingDate}.Id:{Id}", model?.HearingDate, model?.Id);
|
_logger.LogInformation("ReadList. HearingDate:{HearingDate}.Id:{Id}", model?.HearingDate, model?.Id);
|
||||||
var list = model == null ? _hearingStorage.GetFullList() : _hearingStorage.GetFilteredList(model);
|
var list = model == null ? _hearingStorage.GetFullList() : _hearingStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Update(HearingBindingModel model)
|
public bool Update(HearingBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (_hearingStorage.Update(model) == null)
|
if (_hearingStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel lawyer)
|
public bool AddLawyerToHearing(HearingSearchModel model, ILawyerModel lawyer)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
var element = _hearingStorage.GetElement(model);
|
var element = _hearingStorage.GetElement(model);
|
||||||
|
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
return false;
|
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()
|
return true;
|
||||||
{
|
}
|
||||||
Id = element.Id,
|
private void CheckModel(HearingBindingModel model, bool withParams = true)
|
||||||
HearingDate = element.HearingDate,
|
{
|
||||||
Judge = element.Judge,
|
if (model == null)
|
||||||
HearingLawyers = element.HearingLawyers,
|
{
|
||||||
GuarantorId = element.GuarantorId,
|
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;
|
});
|
||||||
}
|
if (element != null && element.Id != model.Id)
|
||||||
private void CheckModel(HearingBindingModel model, bool withParams = true)
|
{
|
||||||
{
|
throw new InvalidOperationException("На данное время уже назначено слушание");
|
||||||
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("На данное время уже назначено слушание");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace LawCompanyContracts.BindingModels
|
namespace LawCompanyContracts.BindingModels
|
||||||
{
|
{
|
||||||
public class HearingBindingModel : IHearingModel
|
public class HearingBindingModel : IHearingModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public DateTime HearingDate { get; set; }
|
public DateTime HearingDate { get; set; }
|
||||||
public string Judge { get; set; } = string.Empty;
|
public string Judge { get; set; } = string.Empty;
|
||||||
public int GuarantorId { get; set; }
|
public int GuarantorId { get; set; }
|
||||||
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,6 @@ namespace LawCompanyContracts.BindingModels
|
|||||||
public string FIO { get; set; } = string.Empty;
|
public string FIO { get; set; } = string.Empty;
|
||||||
public string Phone { get; set; } = string.Empty;
|
public string Phone { get; set; } = string.Empty;
|
||||||
public string Email { 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
|
namespace LawCompanyContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class HearingViewModel : IHearingModel
|
public class HearingViewModel : IHearingModel
|
||||||
{
|
{
|
||||||
[DisplayName("Номер слушания")]
|
[DisplayName("Номер слушания")]
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[DisplayName("Дата слушания")]
|
[DisplayName("Дата слушания")]
|
||||||
public DateTime HearingDate { get; set; }
|
public DateTime HearingDate { get; set; }
|
||||||
[DisplayName("Суд")]
|
[DisplayName("Суд")]
|
||||||
public string Judge { get; set; } = string.Empty;
|
public string Judge { get; set; } = string.Empty;
|
||||||
[DisplayName("Имя поручителя")]
|
public int GuarantorId { get; set; }
|
||||||
public string GuarantorName { get; set; } = string.Empty;
|
public Dictionary<int, ILawyerModel> HearingLawyers { get; set; } = new();
|
||||||
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;
|
public string Phone { get; set; } = string.Empty;
|
||||||
[DisplayName("E-mail юриста")]
|
[DisplayName("E-mail юриста")]
|
||||||
public string Email { get; set; } = string.Empty;
|
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 FIO { get; }
|
||||||
string Phone { get; }
|
string Phone { get; }
|
||||||
string Email { 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 LawCompanyContracts.ViewModels;
|
||||||
using LawCompanyDatabaseImplement.Models;
|
|
||||||
using LawCompanyDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using LawFirmDatabaseImplement.Models;
|
||||||
|
|
||||||
namespace LawFirmDatabaseImplement.Models
|
namespace LawCompanyDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Guarantor : IGuarantorModel
|
public class Guarantor : IGuarantorModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string FIO { get; private set; } = string.Empty;
|
public string FIO { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Email { get; private set; } = string.Empty;
|
public string Email { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Password { get; private set; } = string.Empty;
|
public string Password { get; private set; } = string.Empty;
|
||||||
[ForeignKey("GuarantorId")]
|
[ForeignKey("GuarantorId")]
|
||||||
public virtual List<Hearing> Hearings { get; set; } = new();
|
public virtual List<Hearing> Hearings { get; set; } = new();
|
||||||
[ForeignKey("GuarantorId")]
|
[ForeignKey("GuarantorId")]
|
||||||
public virtual List<Lawyer> Lawyers { get; set; } = new();
|
public virtual List<Lawyer> Lawyers { get; set; } = new();
|
||||||
[ForeignKey("GuarantorId")]
|
[ForeignKey("GuarantorId")]
|
||||||
public virtual List<Consultation> Consultations { get; set; } = new();
|
public virtual List<Consultation> Consultations { get; set; } = new();
|
||||||
|
|
||||||
public static Guarantor? Create(GuarantorBindingModel? model)
|
public static Guarantor? Create(LawCompanyDatabase context, GuarantorBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Guarantor()
|
return new Guarantor()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FIO = model.FIO,
|
FIO = model.FIO,
|
||||||
Email = model.Email,
|
Email = model.Email,
|
||||||
Password = model.Password,
|
Password = model.Password,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Guarantor Create(GuarantorViewModel model)
|
public static Guarantor Create(GuarantorViewModel model)
|
||||||
{
|
{
|
||||||
return new Guarantor
|
return new Guarantor
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FIO = model.FIO,
|
FIO = model.FIO,
|
||||||
Email = model.Email,
|
Email = model.Email,
|
||||||
Password = model.Password,
|
Password = model.Password,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(GuarantorBindingModel? model)
|
public void Update(GuarantorBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FIO = model.FIO;
|
FIO = model.FIO;
|
||||||
Email = model.Email;
|
Email = model.Email;
|
||||||
Password = model.Password;
|
Password = model.Password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GuarantorViewModel GetViewModel => new()
|
public GuarantorViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
FIO = FIO,
|
FIO = FIO,
|
||||||
Email = Email,
|
Email = Email,
|
||||||
Password = Password,
|
Password = Password,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,71 +1,72 @@
|
|||||||
using LawCompanyContracts.BindingModels;
|
using LawCompanyDataModels.Models;
|
||||||
|
using LawCompanyContracts.BindingModels;
|
||||||
using LawCompanyContracts.ViewModels;
|
using LawCompanyContracts.ViewModels;
|
||||||
using LawCompanyDatabaseImplement.Models;
|
|
||||||
using LawCompanyDataModels.Models;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.Design;
|
||||||
|
|
||||||
|
|
||||||
namespace LawFirmDatabaseImplement.Models
|
namespace LawCompanyDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Lawyer : ILawyerModel
|
public class Lawyer : ILawyerModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string FIO { get; private set; } = string.Empty;
|
public string FIO { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Email { get; private set; } = string.Empty;
|
public string Email { get; private set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Phone { get; private set; } = string.Empty;
|
public string Phone { get; private set; } = string.Empty;
|
||||||
[ForeignKey("LawyerId")]
|
[ForeignKey("LawyerId")]
|
||||||
public virtual List<HearingLawyer> HearingLawyers { get; set; } = new();
|
public virtual List<HearingLawyer> HearingLawyers { get; set; } = new();
|
||||||
[ForeignKey("LawyerId")]
|
[ForeignKey("LawyerId")]
|
||||||
public virtual List<ConsultationLawyer> ConsultationLawyers { get; set; } = new();
|
public virtual List<ConsultationLawyer> ConsultationLawyers { get; set; } = new();
|
||||||
public int GuarantorId { get; set; }
|
public int? GuarantorId { get; set; }
|
||||||
|
|
||||||
public static Lawyer? Create(LawyerBindingModel? model)
|
public static Lawyer? Create(LawCompanyDatabase context, LawyerBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Lawyer()
|
return new Lawyer()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FIO = model.FIO,
|
FIO = model.FIO,
|
||||||
Email = model.Email,
|
Email = model.Email,
|
||||||
Phone = model.Phone,
|
Phone = model.Phone,
|
||||||
GuarantorId = model.GuarantorId,
|
GuarantorId = model.GuarantorId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public static Lawyer Create(LawyerViewModel model)
|
public static Lawyer Create(LawyerViewModel model)
|
||||||
{
|
{
|
||||||
return new Lawyer
|
return new Lawyer
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FIO = model.FIO,
|
FIO = model.FIO,
|
||||||
Email = model.Email,
|
Email = model.Email,
|
||||||
Phone = model.Phone,
|
Phone = model.Phone,
|
||||||
GuarantorId = model.GuarantorId,
|
GuarantorId = model.GuarantorId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(LawyerBindingModel? model)
|
public void Update(LawyerBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FIO = model.FIO;
|
FIO = model.FIO;
|
||||||
Email = model.Email;
|
Email = model.Email;
|
||||||
Phone = model.Phone;
|
Phone = model.Phone;
|
||||||
}
|
if (!model.GuarantorId.HasValue) GuarantorId = model.GuarantorId;
|
||||||
public LawyerViewModel GetViewModel => new()
|
}
|
||||||
{
|
public LawyerViewModel GetViewModel => new()
|
||||||
Id = Id,
|
{
|
||||||
FIO = FIO,
|
Id = Id,
|
||||||
Email = Email,
|
FIO = FIO,
|
||||||
Phone = Phone,
|
Email = Email,
|
||||||
GuarantorId = GuarantorId
|
Phone = Phone,
|
||||||
};
|
GuarantorId = GuarantorId
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user