CourseWork_SchoolStudyAgain/SchoolAgainStudy/SchoolAgainStudyDataBaseImplements/Models/Student.cs

74 lines
2.1 KiB
C#

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.Diagnostics;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace SchoolAgainStudyDataBaseImplements.Models
{
public class Student : IStudent
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public int Class { get; set; }
[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("StudentId")]
public virtual List<Interest> Interests { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<Diy> Diys { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<Product> Products { get; set; } = new();
public static Student Create(SchoolDataBase context, StudentBindingModel model)
{
return new Student()
{
Id = model.Id,
Name = model.Name,
Class = model.Class,
Email = model.Email,
Login = model.Login,
Password = model.Password,
};
}
public void Update(StudentBindingModel model)
{
Name = model.Name;
Class = model.Class;
Email = model.Email;
Login = model.Login;
Password = model.Password;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Class = Class,
Email = Email,
Login = Login,
Password = Password
};
}
}