using SchoolAgainStudyContracts.BindingModel; using SchoolAgainStudyContracts.ViewModel; using SchoolAgainStudyDataModels.Models; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SchoolAgainStudyDataBaseImplements.Models { public class Material : IMaterial { [Required] public string Title { get; set; } = string.Empty; [Required] public string SphereUse { get; set; } = string.Empty; public int Id { get; set; } [ForeignKey("MaterialId")] public virtual List LessonMaterials { get; set; } = new(); [ForeignKey("MaterialId")] public virtual List TaskMaterial { get; set; } = new(); [ForeignKey("MaterialId")] public virtual List TeacherMaterial { get; set; } = new(); public static Material? Create(MaterialBindingModel model) { if (model == null) { return null; } return new Material() { Id = model.Id, Title = model.Title, SphereUse = model.SphereUse }; } public static Material Create(MaterialViewModel model) { return new Material { Id = model.Id, Title = model.Title, SphereUse = model.SphereUse }; } public void Update(MaterialBindingModel model) { if (model == null) { return; } Title = model.Title; SphereUse = model.SphereUse; } public MaterialViewModel GetViewModel => new() { Id = Id, Title = Title, SphereUse = SphereUse }; } }