ISEbd-22_CourseWork_School/School/SchoolDataBaseImplement/Models/Account.cs

41 lines
1.4 KiB
C#
Raw Permalink Normal View History

2024-05-01 17:54:58 +04:00
using SchoolContracts.BindingModels;
using SchoolContracts.Extensions;
using SchoolContracts.ViewModels;
using SchoolDataModels;
using System.ComponentModel.DataAnnotations;
namespace SchoolDatabaseImplement.Models
{
public class Account : IAccountModel
{
[Required]
public int StudentByDisciplineId { get; private set; }
[Required]
public DateOnly DateOfAccount { get; private set; }
[Required]
public double Price { get; private set; }
public int Id { get; private set; }
[Required]
public StudentByDisciplineId? StudentByDisciplineId { get; private set; }
public static Account Create(AccountBindingModel model) => model.CastWithCommonProperties<Account, AccountBindingModel>();
public static implicit operator AccountViewModel(Account? model)
{
if (model == null)
{
throw new ArgumentNullException("Возникла ошибка при попытки получить View-модель из null-объекта", nameof(model));
}
var res = model.CastWithCommonProperties<AccountViewModel, Account>();
res.StudentByDisciplineId = model.StudentByDisciplineId;
res.Student = model.StudentByDisciplineId?.Student;
res.Discipline = model.StudentByDisciplineId?.Discipline;
return res;
}
}
}