Case_accounting/CaseAccounting/CaseAccountingDataBaseImplement/Models/Lawyer.cs
2023-04-07 16:35:57 +04:00

87 lines
2.4 KiB
C#

using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataBaseImplement.Models
{
public class Lawyer : ILawyerModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string Patronymic { get; set; } = string.Empty;
[Required]
public int Experience { get; set; }
[Required]
public int SpecializationId { get; set; }
public virtual Specialization Specialization { get; set; } = new();
[Required]
public int UserId { get; set; }
public virtual User User { get; set; } = new();
[ForeignKey("LawyerId")]
public virtual List<CaseLawyer> CaseLawyers { get; set; } = new();
[ForeignKey("LawyerId")]
public virtual List<LawyerContracts> Contracts { get; set; } = new();
public static Lawyer? Create(LawyerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Lawyer()
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Patronymic,
Experience = model.Experience,
SpecializationId = model.SpecializationId,
UserId = model.UserId
};
}
public void Update(LawyerBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Surname = model.Surname;
Patronymic = model.Patronymic;
Experience = model.Experience;
SpecializationId = model.SpecializationId;
}
public LawyerViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
Patronymic = Patronymic,
Experience = Experience,
SpecializationId = SpecializationId,
UserId = UserId
};
}
}