PIbd-22_CourseWork_Hospital.../Polyclinic/HospitalDatabaseImplement/Models/User.cs

60 lines
1.5 KiB
C#
Raw Normal View History

2024-05-01 23:49:06 +04:00
using HospitalContracts.BindingModels;
using HospitalContracts.ViewModels;
using HospitalDataModels.Enums;
using HospitalDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace HospitalDatabaseImplement.Models
{
public class User : IUserModel
{
[Required]
public string FIO { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[Required]
public UserRole Role { get; set; } = UserRole.Неизвестный;
public int Id { get; set; }
public static User? Create(UserBindingModel? model)
{
if (model == null)
{
return null;
}
return new User
{
FIO = model.FIO,
Email = model.Email,
Password = model.Password,
Role = model.Role,
Id = model.Id
};
}
public void Update(UserBindingModel? model)
{
if (model == null)
{
return;
}
FIO = model.FIO;
Email = model.Email;
Password = model.Password;
Role = model.Role;
FIO = model.FIO;
}
public UserViewModel GetViewModel => new()
{
FIO = FIO,
Email = Email,
Password = Password,
Role = Role,
Id = Id
};
}
}