72 lines
1.7 KiB
C#
72 lines
1.7 KiB
C#
using LawCompanyContracts.BindingModels;
|
|
using LawCompanyContracts.ViewModels;
|
|
using LawCompanyDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.ComponentModel.Design;
|
|
|
|
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 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
|
|
};
|
|
}
|
|
}
|