2023-05-17 10:48:52 +04:00

92 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using TaskTrackerContracts.BindingModels;
using TaskTrackerContracts.ViewModels;
namespace TaskTrackerDatabaseImplement;
/// <summary>
/// Сущность &quot;Сотрудник&quot;
/// </summary>
public partial class Employee
{
/// <summary>
/// Идентификатор сущности &quot;Сотрудник&quot;
/// </summary>
public int Id { get; set; }
/// <summary>
/// ФИО сотрудника
/// </summary>
public string Name { get; set; } = null!;
/// <summary>
/// Должность сотрудника
/// </summary>
public string JobTitle { get; set; } = null!;
/// <summary>
/// E-mail сотрудника
/// </summary>
public string Email { get; set; } = null!;
/// <summary>
/// Ссылка на идентификатор компании в которой работает сотрудник
/// </summary>
public int? CompanyId { get; set; }
public virtual Company Company { get; set; } = null!;
public virtual ICollection<TaskAssigment> TaskAssigments { get; set; } = new List<TaskAssigment>();
public static Employee? Create(EmployeeBindingModel model)
{
if (model == null)
{
return null;
}
return new Employee()
{
Name = model.Name,
Email = model.Email,
JobTitle = model.JobTitle,
CompanyId = model.CompanyId,
Id = model.Id
};
}
public static Employee Create(EmployeeViewModel model)
{
return new Employee()
{
Name = model.Name,
Email = model.Email,
JobTitle = model.JobTitle,
CompanyId = model.CompanyId,
Id = model.Id
};
}
public void Update(EmployeeBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Email = model.Email;
JobTitle = model.JobTitle;
CompanyId = model.CompanyId;
}
public EmployeeViewModel GetViewModel => new()
{
Name = Name,
Email = Email,
JobTitle = JobTitle,
CompanyId = CompanyId,
Id = Id
};
}