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; /// /// Работы /// [ForeignKey("WorkerId")] public virtual List Works { get; set; } = new(); /// /// Статьи затрат /// [ForeignKey("WorkerId")] public virtual List Items { get; set; } = new(); public static Worker? Create(WorkerBindingModel? model) { if (model == null) { return null; } return new() { 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 }; } }