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

53 lines
1.0 KiB
C#
Raw Normal View History

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 Department : IDepartmentModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public long Telephone { get; set; }
public int Id { get; set; }
public static Department? Create(DepartmentBindingModel model)
{
if (model == null)
{
return null;
}
return new Department
{
Id = model.Id,
Name = model.Name,
Telephone = model.Telephone
};
}
public void Update(DepartmentBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Telephone = model.Telephone;
}
public DepartmentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Telephone = Telephone
};
}
}