PIbd-23_Elatomtsev_L.K._Cou.../Bank/BankDatabaseImplement/Models/Term.cs

44 lines
1.2 KiB
C#

using BankDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using BankContracts.BindingModels;
using BankContracts.ViewModels;
namespace BankDatabaseImplement.Models
{
public class Term : ITermModel
{
public int Id { get; set; }
[Required]
public int Duration { get; set; }
[Required]
public int ProgramId { get; set; }
public virtual Program? Program { get; set; }
public static Term? Create(TermBindingModel model)
{
if (model == null)
return null;
return new Term
{
Id = model.Id,
Duration = model.Duration,
ProgramId = model.ProgramId,
};
}
public void Update(TermBindingModel model)
{
if (model == null)
return;
Id = model.Id;
Duration = model.Duration;
ProgramId = model.ProgramId;
}
public TermViewModel GetViewModel => new()
{
Id = Id,
Duration = Duration,
ProgramId = ProgramId,
};
}
}