ISEbd-21_Melnikov_I.O._CarS.../CarService/CarServiceDatabase/Models/Worker.cs

66 lines
1.5 KiB
C#

using CarServiceContracts.BindingModels;
using CarServiceContracts.Models;
using CarServiceContracts.ViewModels;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace CarServiceDatabase.Models
{
public class Worker : IWorkerModel
{
public int Id { get; private set; }
[Required]
public string Login { get; private set; } = string.Empty;
[Required]
public string Password { get; private set; } = string.Empty;
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public string Surname { get; private set; } = string.Empty;
/// <summary>
/// Работы
/// </summary>
[ForeignKey("WorkerId")]
public virtual List<Work> Works { get; set; } = new();
/// <summary>
/// Статьи затрат
/// </summary>
[ForeignKey("WorkerId")]
public virtual List<Item> Items { get; set; } = new();
public static Worker? Create(WorkerBindingModel? model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
Login = model.Login,
Password = model.Password,
Name = model.Name,
Surname = model.Surname
};
}
public void Update(WorkerBindingModel? model)
{
if (model == null)
{
return;
}
Login = model.Login;
Password = model.Password;
Name = model.Name;
Surname = model.Surname;
}
public WorkerViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Password = Password,
Name = Name,
Surname = Surname
};
}
}