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

76 lines
1.8 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 Deal : IDealModel
{
[Required]
public DateTime DateFrom { get; set; }
public DateTime? DateTo { get; set; }
[Required]
public int PositionId { get; set; }
[Required]
public int EmployeeId { get; set; }
[Required]
public int DepartmentId { get; set; }
[Required]
public int TypeId { get; set; }
public int Id { get; set; }
public virtual Position Position { get; set; }
public virtual Employee Employee { get; set; }
public virtual Department Department { get; set; }
public virtual Type Type { get; set; }
public static Deal? Create(DealBindingModel model)
{
if(model == null)
{
return null;
}
return new Deal
{
Id = model.Id,
DateFrom = model.DateFrom,
DateTo = model.DateTo,
PositionId = model.PositionId,
EmployeeId = model.EmployeeId,
DepartmentId = model.DepartmentId,
TypeId = model.TypeId
};
}
public void Update(DealBindingModel model)
{
if (model == null)
{
return;
}
DateFrom = model.DateFrom;
DateTo = model.DateTo;
}
public DealViewModel GetViewModel => new()
{
Id = Id,
DateFrom = DateFrom,
DateTo = DateTo,
PositionId = PositionId,
EmployeeId = EmployeeId,
DepartmentId = DepartmentId,
TypeId = TypeId,
PositionName = Position.Name,
DepartmentName = Department.Name,
EmployeeName = Employee.LastName + Employee.FirstName + Employee.Patronymic,
TypeName = Type.Name
};
}
}