PIbd-32_Artamonova_T.V._COP_2/UniversityDatabaseImplement/Models/Student.cs

67 lines
2.0 KiB
C#
Raw Normal View History

2023-10-28 09:06:35 +04:00
using System.ComponentModel.DataAnnotations;
using UniversityDataModels.Models;
using UniversityContracts.BindingModels;
using UniversityContracts.ViewModels;
namespace UniversityDatabaseImplement.Models
{
public class Student : IStudentModel
{
public int Id { get; private set; }
[Required]
public string FIO { get; private set; } = string.Empty;
[Required]
public string Email { get; private set; } = string.Empty;
[Required]
public string PhotoFilePath { get; private set; } = string.Empty;
[Required]
public string DirectionName { get; private set; } = string.Empty;
public static Student? Create(StudentBindingModel model)
{
if (model == null)
{
return null;
}
return new Student()
{
Id = model.Id,
FIO = model.FIO,
Email = model.Email,
PhotoFilePath = model.PhotoFilePath,
DirectionName = model.DirectionName
};
}
public static Student Create(StudentViewModel model)
{
return new Student()
{
Id = model.Id,
FIO = model.FIO,
Email = model.Email,
PhotoFilePath = model.PhotoFilePath,
DirectionName = model.DirectionName
};
}
public void Update(StudentBindingModel model)
{
if (model == null)
{
return;
}
FIO = model.FIO;
Email = model.Email;
PhotoFilePath = model.PhotoFilePath;
DirectionName = model.DirectionName;
}
public StudentViewModel GetViewModel => new()
{
Id = Id,
FIO = FIO,
Email = Email,
PhotoFilePath = PhotoFilePath,
DirectionName = DirectionName
};
}
}