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

89 lines
2.1 KiB
C#

using BeautySaloonContracts.BindingModels;
using BeautySaloonContracts.ViewModels;
using BeautySaloonDataModels;
namespace BeautySaloonDatabaseImplement;
/// <summary>
/// Сущность сотрудники
/// </summary>
public partial class Employee : IEmployeeModel
{
/// <summary>
/// Уникальный идентификатор
/// </summary>
public int Id { get; set; }
/// <summary>
/// Имя
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Фамилия
/// </summary>
public string Surname { get; set; } = null!;
/// <summary>
/// Отчество
/// </summary>
public string? Patronymic { get; set; }
/// <summary>
/// Номер телефона
/// </summary>
public string Phone { get; set; } = null!;
/// <summary>
/// Идентификатор позиции
/// </summary>
public int PositionId { get; set; }
public virtual ICollection<Order> Orders { get; } = new List<Order>();
public virtual Position Position { get; set; } = null!;
public virtual ICollection<ServiceOrder> ServiceOrders { get; } = new List<ServiceOrder>();
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,
};
}