71 lines
1.6 KiB
C#
71 lines
1.6 KiB
C#
|
using Contracts.BindingModels;
|
|||
|
using Contracts.ViewModels;
|
|||
|
using DataModels.Models;
|
|||
|
using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
using System.ComponentModel.DataAnnotations;
|
|||
|
|
|||
|
namespace DatabaseImplement.Models
|
|||
|
{
|
|||
|
public class Guarantor : IGuarantorModel
|
|||
|
{
|
|||
|
public int Id { get; set; }
|
|||
|
[Required]
|
|||
|
public string Email { get; set; } = string.Empty;
|
|||
|
[Required]
|
|||
|
public string Name { get; set; } = string.Empty;
|
|||
|
[Required]
|
|||
|
public string Login { get; set; } = string.Empty;
|
|||
|
[Required]
|
|||
|
public string Password { get; set; } = string.Empty;
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Machine> Machines { get; set; } = new();
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Worker> Workers { get; set; } = new();
|
|||
|
[ForeignKey("UserId")]
|
|||
|
public virtual List<Workshop> Workshops { get; set; } = new();
|
|||
|
|
|||
|
public static Guarantor? Create(GuarantorBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new Guarantor
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Email = model.Email,
|
|||
|
Name = model.Name,
|
|||
|
Login = model.Login,
|
|||
|
Password = model.Password
|
|||
|
};
|
|||
|
}
|
|||
|
public static Guarantor Create(GuarantorViewModel model)
|
|||
|
{
|
|||
|
return new Guarantor
|
|||
|
{
|
|||
|
Id = model.Id,
|
|||
|
Email = model.Email,
|
|||
|
Name = model.Name,
|
|||
|
Login = model.Login,
|
|||
|
Password = model.Password
|
|||
|
};
|
|||
|
}
|
|||
|
public void Update(GuarantorBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
return;
|
|||
|
Email = model.Email;
|
|||
|
Name = model.Name;
|
|||
|
Password = model.Password;
|
|||
|
}
|
|||
|
public GuarantorViewModel GetViewModel => new()
|
|||
|
{
|
|||
|
Id = Id,
|
|||
|
Email = Email,
|
|||
|
Name = Name,
|
|||
|
Login = Login,
|
|||
|
Password = Password
|
|||
|
};
|
|||
|
}
|
|||
|
}
|