using StudentPerformanceContracts.BindingModels; using StudentPerformanceContracts.ViewModels; using StudentPerformanceDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; namespace StudentPerformanceDatabaseImplement.Models { public class Students : IStudentModel { [Required] public string Fullname { get; set; } = string.Empty; // Средний балл по сесии (не более 6 сессий) public List AverageScore { get; set; } = new List(); public int Id { get; private set; } public int FormatId { get; set; } public virtual Formats Format { get; set; } = new(); public DateTime AdmissionDate { get; set; } public static Students? Create(StudentsDatabase context, StudentBindingModel? model) { if (model == null) { return null; } return new Students() { Id = model.Id, Fullname = model.Fullname, Format = context.Formats.First(x => x.Id == model.FormatId), AverageScore = model.AverageScore, AdmissionDate = model.AdmissionDate.ToUniversalTime() }; } public void Update(StudentBindingModel? model, StudentsDatabase context) { if (model == null) { return; } Fullname = model.Fullname; Format = context.Formats.First(x => x.Id == model.Id); AverageScore = model.AverageScore.ToList(); AdmissionDate = model.AdmissionDate.ToUniversalTime(); } public StudentViewModel GetViewModel => new() { Id = Id, Fullname = Fullname, FormatId = Format.Id, Format = Format.Name, AverageScore = AverageScore, AdmissionDate = AdmissionDate, }; } }