CourseWork_SchoolStudyAgain/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Models/Material.cs

76 lines
2.1 KiB
C#
Raw Normal View History

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;
[Required]
public int TeacherId { get; set; }
public virtual Teacher Teacher { get; set; }
public int Id { get; set; }
[ForeignKey("MaterialId")]
public virtual List<LessonMaterial> LessonMaterials { get; set; } = new();
[ForeignKey("MaterialId")]
public virtual List<TaskMaterial> TaskMaterial { 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,
TeacherId = model.TeacherId,
};
}
public static Material Create(MaterialViewModel model)
{
return new Material
{
Id = model.Id,
Title = model.Title,
SphereUse = model.SphereUse,
TeacherId=model.TeacherId
};
}
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,
TeacherId = TeacherId,
};
}
}