CourseWork_KPO/CandidateReviewDatabaseImplement/Models/User.cs

112 lines
3.5 KiB
C#

using CandidateReviewContracts.BindingModels;
using CandidateReviewContracts.ViewModels;
using CandidateReviewDataModels.Enums;
using CandidateReviewDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CandidateReviewDatabaseImplement.Models
{
public class User : IUserModel
{
public int? CompanyId { get; set; }
[Required]
public string Surname { get; set; } = string.Empty;
[Required]
public string Name { get; set; } = string.Empty;
public string? LastName { get; set; }
public string? AvatarFilePath { get; set; }
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
public string? PhoneNumber { get; set; }
[Required]
public bool EmailConfirmed { get; set; }
[Required]
public RoleEnum Role { get; set; }
public int Id { get; set; }
public virtual Company Company { get; set; }
[ForeignKey("UserId")]
public virtual List<Resume> Resumes { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Assessment> Assessments { get; set; } = new();
public static User? Create(UserBindingModel model)
{
if (model == null)
{
return null;
}
return new User()
{
Id = model.Id,
Surname = model.Surname,
Name = model.Name,
LastName = model.LastName,
AvatarFilePath = model.AvatarFilePath,
Email = model.Email,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
EmailConfirmed = model.EmailConfirmed,
Role = model.Role,
CompanyId = model.CompanyId
};
}
public static User Create(UserViewModel model)
{
return new User
{
Id = model.Id,
Surname = model.Surname,
Name = model.Name,
LastName = model.LastName,
AvatarFilePath = model.AvatarFilePath,
Email = model.Email,
Password = model.Password,
PhoneNumber = model.PhoneNumber,
EmailConfirmed = model.EmailConfirmed,
Role = model.Role,
CompanyId = model.CompanyId
};
}
public void Update(UserBindingModel model)
{
if (model == null)
{
return;
}
Surname = model.Surname;
Name = model.Name;
LastName = model.LastName;
AvatarFilePath = model.AvatarFilePath;
Email = model.Email;
Password = model.Password;
PhoneNumber = model.PhoneNumber;
EmailConfirmed = model.EmailConfirmed;
Role = model.Role;
CompanyId = model.CompanyId;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Surname = Surname,
LastName = LastName,
AvatarFilePath = AvatarFilePath,
Email = Email,
Password = Password,
PhoneNumber = PhoneNumber,
EmailConfirmed = EmailConfirmed,
Role = Role,
CompanyId = CompanyId
};
}
}