PIbd-22_Filippov_D.S._Cours.../VeterinaryDatabaseImplement/Models/Owner.cs

67 lines
1.5 KiB
C#
Raw Permalink Normal View History

2024-05-30 07:33:38 +04:00
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using VeterinaryContracts.BindingModels;
using VeterinaryContracts.ViewModels;
using VeterinaryDataModels.Models;
namespace VeterinaryDatabaseImplement.Models
{
public class Owner : IOwnerModel
{
public int Id { get; private set; }
[Required]
public string OwnerFIO { get; private set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("OwnerId")]
public virtual List<Pet> Pets { get; set; } = new();
[ForeignKey("OwnerId")]
public virtual List<Visit> Visits { get; set; } = new();
[ForeignKey("OwnerId")]
public virtual List<Purchase> Purchases { get; set; } = new();
public static Owner? Create(OwnerBindingModel model)
{
if (model == null)
{
return null;
}
return new Owner()
{
Id = model.Id,
OwnerFIO = model.OwnerFIO,
Login = model.Login,
Password = model.Password
};
}
public static Owner Create(OwnerViewModel model)
{
return new Owner()
{
Id = model.Id,
OwnerFIO = model.OwnerFIO,
Login = model.Login,
Password = model.Password
};
}
public void Update(OwnerBindingModel model)
{
if (model == null)
{
return;
}
OwnerFIO = model.OwnerFIO;
Login = model.Login;
Password = model.Password;
}
public OwnerViewModel GetViewModel => new()
{
Id = Id,
OwnerFIO = OwnerFIO,
Login = Login,
Password = Password
};
}
}