PIbd-21_Pyatakov_KM_Markov_.../UniversityDataBaseImplemet/Models/Student.cs
Danil Markov 96a6d6bbf7 Список word и excel сделан.
Почти сделан pdf (добавил вспомогательный viewmodel так как C# не умеет в кортежи).
Нужно доделать pdf с отправкой на почту и навести красоту (стили, валидацию)
2023-05-18 21:57:00 +04:00

75 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
using UniversityModels.Models;
namespace UniversityDataBaseImplemet.Models
{
public class Student : IStudentModel
{
public int Id { get; private set; }
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public DateTime DateOfBirth { get; set; }
[Required]
public DateTime DateOfAddmission { get; set; }
[Required]
public int StudentCard { get; set; }
public int? EducationStatusId { get; set; }
[Required]
public int UserId { get; set; }
[ForeignKey("StudentId")]
public virtual List<StudentDocument> DocumentStudents { get; set; } = new();
[ForeignKey("StudentId")]
public virtual List<StudentStream> StudentStream { get; set; } = new();
public virtual EducationStatus? EducationStatus { get; set; }
public virtual User User { get; set; }
public static Student Create(StudentBindingModel model)
{
return new Student()
{
Id = model.Id,
Name = model.Name,
Surname = model.Surname,
DateOfBirth = model.DateOfBirth,
DateOfAddmission = model.DateOfAddmission,
StudentCard = model.StudentCard,
EducationStatusId = model.EducationStatusId,
UserId = model.UserId
};
}
public void Update(StudentBindingModel model)
{
Name = model.Name;
Surname = model.Surname;
DateOfBirth = model.DateOfBirth;
DateOfAddmission = model.DateOfAddmission;
StudentCard = model.StudentCard;
EducationStatusId = model.EducationStatusId;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
DateOfBirth = DateOfBirth,
DateOfAddmission = DateOfAddmission,
StudentCard = StudentCard,
EducationStatusId = EducationStatusId,
UserId = UserId,
EducationStatusName = EducationStatus?.Name ?? "Не указан"
};
}
}