Coursach/Course/DatabaseImplement/Models/Implementer.cs

72 lines
1.6 KiB
C#
Raw Normal View History

2024-04-24 12:35:17 +04:00
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2024-04-21 20:36:07 +04:00
namespace DatabaseImplement.Models
{
2024-04-24 12:35:17 +04:00
public class Implementer : IImplementerModel
2024-04-21 20:36:07 +04:00
{
2024-04-24 12:35:17 +04:00
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<Detail> Details { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Product> Products { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Production> Productions { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer
{
Id = model.Id,
Email = model.Email,
Name = model.Name,
Login = model.Login,
Password = model.Password
};
}
public static Implementer Create(ImplementerViewModel model)
{
return new Implementer
{
Id = model.Id,
Email = model.Email,
Name = model.Name,
Login = model.Login,
Password = model.Password
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
return;
Email = model.Email;
Name = model.Name;
Password = model.Password;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Email = Email,
Name = Name,
Login = Login,
Password = Password
};
2024-04-21 20:36:07 +04:00
}
}