67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
|
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
|
|||
|
};
|
|||
|
}
|
|||
|
}
|