74 lines
1.7 KiB
C#
74 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 Worker : IWorkerModel
|
|
{
|
|
public int Id { get; set; }
|
|
[Required]
|
|
public string Name { get; set; } = string.Empty;
|
|
[Required]
|
|
public DateTime Birthday { get; set; }
|
|
[Required]
|
|
public string Specialization { get; set; } = string.Empty;
|
|
[Required]
|
|
public double Salary { get; set; }
|
|
[Required]
|
|
public int UserId { get; set; }
|
|
[ForeignKey("WorkerId")]
|
|
public virtual List<WorkerMachine> WorkerMachines { get; set; } = new();
|
|
[ForeignKey("WorkerId")]
|
|
public virtual List<WorkerWorkshop> WorkerWorkshops { get; set; } = new();
|
|
public virtual Guarantor Guarantor { get; set; }
|
|
public static Worker? Create(WorkerBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Worker
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Birthday = model.Birthday,
|
|
Specialization = model.Specialization,
|
|
Salary = model.Salary,
|
|
UserId = model.UserId
|
|
};
|
|
}
|
|
public static Worker Create(WorkerViewModel model)
|
|
{
|
|
return new Worker
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
Birthday = model.Birthday,
|
|
Specialization = model.Specialization,
|
|
Salary = model.Salary,
|
|
UserId = model.UserId
|
|
};
|
|
}
|
|
public void Update(WorkerBindingModel model)
|
|
{
|
|
if (model == null)
|
|
return;
|
|
Name = model.Name;
|
|
Specialization = model.Specialization;
|
|
Salary = model.Salary;
|
|
}
|
|
public WorkerViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
Birthday = Birthday,
|
|
Specialization = Specialization,
|
|
Salary = Salary,
|
|
UserId = UserId
|
|
};
|
|
}
|
|
}
|