PIbd-32_Artamonova_T.V._COP_2/UniversityDatabaseImplement/Models/Direction.cs

49 lines
1.2 KiB
C#

using System.ComponentModel.DataAnnotations;
using UniversityDataModels.Models;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
namespace UniversityDatabaseImplement.Models
{
public class Direction : IDirectionModel
{
public int Id { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
public static Direction? Create(DirectionBindingModel model)
{
if (model == null)
{
return null;
}
return new Direction()
{
Id = model.Id,
Name = model.Name
};
}
public static Direction Create(DirectionViewModel model)
{
return new Direction()
{
Id = model.Id,
Name = model.Name
};
}
public void Update(DirectionBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public DirectionViewModel GetViewModel => new()
{
Id = Id,
Name = Name
};
}
}