2024-04-27 21:24:12 +04:00
|
|
|
|
using LawFimDataModels.Models;
|
|
|
|
|
using LawFirmContracts.BindingModels;
|
|
|
|
|
using LawFirmContracts.ViewModels;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-05-01 02:47:39 +04:00
|
|
|
|
using System.ComponentModel.Design;
|
2024-04-27 21:24:12 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace LawFirmDatabaseImplement.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")]
|
2024-04-27 22:16:36 +04:00
|
|
|
|
public virtual List<ConsultationLawyer> ConsultationLawyers { get; set; } = new();
|
2024-05-01 02:47:39 +04:00
|
|
|
|
public int? GuarantorId { get; set; }
|
2024-04-27 21:24:12 +04:00
|
|
|
|
|
2024-05-01 02:47:39 +04:00
|
|
|
|
public static Lawyer? Create(LawFirmDatabase context, LawyerBindingModel? model)
|
2024-04-27 21:24:12 +04:00
|
|
|
|
{
|
|
|
|
|
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;
|
2024-05-01 02:47:39 +04:00
|
|
|
|
if (!model.GuarantorId.HasValue) GuarantorId = model.GuarantorId;
|
2024-04-27 21:24:12 +04:00
|
|
|
|
}
|
|
|
|
|
public LawyerViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
Id = Id,
|
|
|
|
|
FIO = FIO,
|
|
|
|
|
Email = Email,
|
|
|
|
|
Phone = Phone,
|
|
|
|
|
GuarantorId = GuarantorId
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|