SUBD_PIbd-21_Balberova_D.N./BeautySaloon/BeautySaloonDatabaseImplement/Models/Employee.cs

71 lines
2.0 KiB
C#
Raw Normal View History

using BeautySaloonContracts.BindingModels;
using BeautySaloonContracts.ViewModels;
using BeautySaloonDataModels;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace BeautySaloonDatabaseImplement.Models
{
public class Employee : IEmployeeModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
public string Patronymic { get; set; } = string.Empty;
[Required]
public string Phone { get; set; } = string.Empty;
[Required]
public int PositionId { get; set; }
public Position Position { get; set; }
[ForeignKey("EmployeeId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("EmployeeId")]
public virtual List<ServiceOrder> OrderServices { get; set; } = new();
public static Employee? Create(EmployeeBindingModel? model)
{
if (model == null)
{
return null;
}
return new Employee()
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
Patronymic = model.Patronymic,
Phone = model.Phone,
PositionId = model.PositionId
};
}
public void Update(EmployeeBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Surname = model.Surname;
Patronymic = model.Patronymic;
Phone = model.Phone;
PositionId = model.PositionId;
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
Patronymic = Patronymic,
Phone = Phone,
PositionId = PositionId,
PositionName = Position.Name,
};
}
}