using SchoolContracts.BindingModels; using SchoolContracts.Extensions; using SchoolContracts.ViewModels; using SchoolDataModels; using System.ComponentModel.DataAnnotations; namespace SchoolDatabaseImplement.Models { public class Student : IStudentModel { [Required] public int ExecutorId { get; private set; } [Required] public string Name { get; private set; } = string.Empty; [Required] public double Price { get; private set; } [Required] public int Course { get; private set; } public int Id { get; private set; } [Required] public Executor? Executor { get; private set; } [Required] public List Disciplines { get; private set; } = new(); public static Student Create(StudentBindingModel model) => model.CastWithCommonProperties(); public static implicit operator StudentViewModel?(Student? model) { if (model == null) { return null; } var res = model.CastWithCommonProperties(); res.DirectorLogin = model.Executor?.Login ?? string.Empty; res.Disciplines = model.Disciplines.Select(x => (DisciplineViewModel)x.Discipline).ToList(); return res; } public void Update(StudentBindingModel model) { Price = model.Price; Course = model.Course; } public StudentViewModel GetViewModel() => this.CastWithCommonProperties(); } }