CourseWork_SchoolStudyAgain/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Models/Teacher.cs

72 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.Security.Claims;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyDataBaseImplements.Models
{
public class Teacher : ITeacher
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Post { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
public int Id { get; set; }
[ForeignKey("TeacherId")]
public virtual List<Material> Materials { get; set; } = new();
[ForeignKey("TeacherId")]
public virtual List<Task> Tasks { get; set; } = new();
[ForeignKey("TeacherId")]
public virtual List<Lesson> Lessons { get; set; } = new();
public static Teacher Create(SchoolDataBase context, TeacherBindingModel model)
{
return new Teacher()
{
Id = model.Id,
Name = model.Name,
Post = model.Post,
Email = model.Email,
Login = model.Login,
Password = model.Password,
};
}
public void Update(TeacherBindingModel model)
{
Name = model.Name;
Post = model.Post;
Email = model.Email;
Login = model.Login;
Password = model.Password;
}
public TeacherViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Post = Post,
Email = Email,
Login = Login,
Password = Password,
};
}
}