PIbd-22_Bondarenko_M.S_SUBD/PersonnelDepartmentView/PersonnelDepartmentDatabaseImplement/Models/Employee.cs

57 lines
1.2 KiB
C#

using PersonnelDepartmentContracts.BindingModels;
using PersonnelDepartmentContracts.ViewModels;
using PersonnelDepartmentDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PersonnelDepartmentDatabaseImplement.Models
{
public class Employee : IEmployeeModel
{
[Required]
public string FirstName { get; set; } = string.Empty;
[Required]
public string LastName { get; set; } = string.Empty;
public string Patronymic { get; set; } = string.Empty;
public int Id { get; set; }
public static Employee? Create(EmployeeBindingModel model)
{
if (model == null)
{
return null;
}
return new Employee
{
Id = model.Id,
FirstName = model.FirstName,
LastName = model.LastName,
Patronymic = model.Patronymic
};
}
public void Update(EmployeeBindingModel model)
{
if (model == null)
{
return;
}
FirstName = model.FirstName;
LastName = model.LastName;
Patronymic = model.Patronymic;
}
public EmployeeViewModel GetViewModel => new()
{
Id = Id,
FirstName = FirstName,
LastName = LastName,
Patronymic = Patronymic
};
}
}