PIbd-22_Fedorenko_Puchkina_.../LawFim/LawFirmDatabaseImplement/Models/Client.cs

66 lines
1.8 KiB
C#

using LawFimDataModels.Models;
using LawFirmContracts.BindingModels;
using LawFirmContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace LawFirmDatabaseImplement.Models
{
public class Client : IClientModel
{
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("ClientId")]
public virtual List<CaseClient> CaseClients { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<VisitClient> ClientVisits { get; set; } = new();
public static Client? Create(ClientBindingModel? model)
{
if (model == null)
{
return null;
}
return new Client()
{
Id = model.Id,
FIO = model.FIO,
Email = model.Email,
Phone = model.Phone,
};
}
public static Client Create(ClientViewModel model)
{
return new Client
{
Id = model.Id,
FIO = model.FIO,
Email = model.Email,
Phone = model.Phone,
};
}
public void Update(ClientBindingModel? model)
{
if (model == null)
{
return;
}
FIO = model.FIO;
Email = model.Email;
Phone = model.Phone;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
FIO = FIO,
Email = Email,
Phone = Phone,
};
}
}