68 lines
1.8 KiB
C#
68 lines
1.8 KiB
C#
using SYBDContracts.BindingModels;
|
|
using SYBDContracts.ViewModels;
|
|
using SYBDDataModels.Models;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
|
|
namespace SYBDDatabaseImplement.Models
|
|
{
|
|
public class Insurance : IInsuranceModel
|
|
{
|
|
public int Id { get; private set; }
|
|
|
|
[Required]
|
|
public string Name { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Address { get; private set; } = string.Empty;
|
|
|
|
[Required]
|
|
public string Phone { get; private set; } = string.Empty;
|
|
[ForeignKey("InsuranceId")]
|
|
public virtual List<Order> Orders { get; set; } = new();
|
|
public static Insurance? Create(InsuranceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Insurance()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Address = model.Address,
|
|
Phone = model.Phone,
|
|
};
|
|
}
|
|
|
|
public static Insurance Create(InsuranceViewModel model)
|
|
{
|
|
return new Insurance
|
|
{
|
|
Id = model.Id,
|
|
Address = model.Address,
|
|
Name = model.Name,
|
|
Phone = model.Phone,
|
|
};
|
|
}
|
|
|
|
public void Update(InsuranceBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
Address = model.Address;
|
|
Phone = model.Phone;
|
|
}
|
|
|
|
public InsuranceViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Address = Address,
|
|
Phone = Phone,
|
|
};
|
|
}
|
|
} |