ISEbd-22_CourseWork_School/School/SchoolDataBaseImplement/Models/Student.cs

51 lines
1.6 KiB
C#
Raw Normal View History

2024-05-01 17:54:58 +04:00
using SchoolContracts.BindingModels;
using SchoolContracts.Extensions;
using SchoolContracts.ViewModels;
using SchoolDataModels;
using System.ComponentModel.DataAnnotations;
namespace SchoolDatabaseImplement.Models
{
public class Student : IStudentModel
{
[Required]
public int ExecutorId { get; private set; }
[Required]
public string Name { get; private set; } = string.Empty;
[Required]
public double Price { get; private set; }
[Required]
public int Course { get; private set; }
public int Id { get; private set; }
[Required]
public Executor? Executor { get; private set; }
[Required]
public List<StudentByDiscipline> Disciplines { get; private set; } = new();
public static Student Create(StudentBindingModel model) => model.CastWithCommonProperties<Student, StudentBindingModel>();
public static implicit operator StudentViewModel?(Student? model)
{
if (model == null)
{
return null;
}
var res = model.CastWithCommonProperties<StudentViewModel, Student>();
res.DirectorLogin = model.Executor?.Login ?? string.Empty;
res.Disciplines = model.Disciplines.Select(x => (DisciplineViewModel)x.Discipline).ToList();
return res;
}
public void Update(StudentBindingModel model)
{
Price = model.Price;
Course = model.Course;
}
public StudentViewModel GetViewModel() => this.CastWithCommonProperties<StudentViewModel, Student>();
}
}