Coursach/Course/DatabaseImplement/Models/Implementer.cs
Sergey Kozyrev f502a218a7 FixDatabase + UpdateView
Заряжай, заря-заря-жай, заряжай меня
Мне не спрятаться от тебя и не убежать
2024-04-30 17:03:49 +04:00

73 lines
1.7 KiB
C#

using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DatabaseImplement.Models
{
public class Implementer : IImplementerModel
{
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;
Login = model.Login;
Password = model.Password;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Email = Email,
Name = Name,
Login = Login,
Password = Password
};
}
}