2024-04-23 21:50:08 +04:00
|
|
|
|
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();
|
2024-04-27 23:00:03 +04:00
|
|
|
|
public int ExecutorId { get; set; }
|
2024-04-23 21:50:08 +04:00
|
|
|
|
|
|
|
|
|
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,
|
2024-04-27 23:00:03 +04:00
|
|
|
|
ExecutorId = model.ExecutorId,
|
2024-04-23 21:50:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static Client Create(ClientViewModel model)
|
|
|
|
|
{
|
|
|
|
|
return new Client
|
|
|
|
|
{
|
|
|
|
|
Id = model.Id,
|
|
|
|
|
FIO = model.FIO,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
Phone = model.Phone,
|
2024-04-27 23:00:03 +04:00
|
|
|
|
ExecutorId = model.ExecutorId,
|
2024-04-23 21:50:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
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,
|
2024-04-27 23:00:03 +04:00
|
|
|
|
ExecutorId = ExecutorId,
|
2024-04-23 21:50:08 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|