Files
mmorales.photo/back/DataModels/UserModel.cs
2025-08-15 20:03:07 +02:00

54 lines
1.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace back.DataModels;
[Table("Users")]
public class UserModel : PersonModel
{
[Required]
public string Email { get; set; }
[Required, MinLength(8)]
public string Password { get; set; }
[Required]
public string Salt { get; set; }
[ForeignKey("RoleId")]
public List<RoleModel> Role { get; set; }
public UserModel(string id, string email, string password, string name, List<RoleModel> role, DateTime createdAt, DateTime updatedAt)
: base(id, name)
{
Email = email;
Password = password;
Role = role;
CreatedAt = createdAt;
UpdatedAt = updatedAt;
}
public UserModel() { }
public bool IsAdmin => Role.Exists(r => r.IsAdmin);
public bool IsContentManager => Role.Exists(r => r.IsContentManager);
public bool IsUser => Role.Exists(r => r.IsUser);
public UserDto ToDto()
{
return new UserDto
{
Id = Id,
Name = Name,
Email = Email,
ProfilePicture = ProfilePicture,
Avatar = Avatar,
SocialMedia = SocialMedia,
Bio = Bio,
CreatedAt = CreatedAt,
UpdatedAt = UpdatedAt
};
}
}
public class UserDto : PersonModel
{
public required string Email { get; set; }
}