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(); public static implicit operator AccountViewModel(Account? model) { if (model == null) { throw new ArgumentNullException("Возникла ошибка при попытки получить View-модель из null-объекта", nameof(model)); } var res = model.CastWithCommonProperties(); res.StudentByDisciplineId = model.StudentByDisciplineId; res.Student = model.StudentByDisciplineId?.Student; res.Discipline = model.StudentByDisciplineId?.Discipline; return res; } } }