60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
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 TaskTrackerContracts.BindingModels;
|
|
using TaskTrackerContracts.BusinessLogicsContracts;
|
|
using TaskTrackerContracts.ViewModels;
|
|
using TaskTrackerDataModels.Models;
|
|
|
|
namespace TaskTrackerDatabase.Models
|
|
{
|
|
public class Student : IStudentModel
|
|
{
|
|
public int Id { get; set; }
|
|
|
|
[Required]
|
|
public string Name { get; set; } = string.Empty;
|
|
[Required]
|
|
|
|
public DateTime DateBirth { get; set; }
|
|
[ForeignKey("StudentId")]
|
|
public virtual List<Result> Results { get; set; } = new();
|
|
[ForeignKey("StudentId")]
|
|
public virtual List<Exam> Exams { get; set; } = new();
|
|
public static Student? Create(StudentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new Student()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
DateBirth = model.DateBirth,
|
|
};
|
|
}
|
|
|
|
public void Update(StudentBindingModel? model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
DateBirth = model.DateBirth;
|
|
}
|
|
|
|
public StudentViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
DateBirth = DateBirth,
|
|
};
|
|
}
|
|
}
|