using SiteManagementSystem_SoftwareEngineering_.Model; using SiteManagementSystem_SoftwareEngineering_.Service; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Security.Claims; namespace SiteManagementSystem_SoftwareEngineering_.Entity { public class User : ICloneable { public User() { } public User(UserModel model) { Name = model.Name; RoleName = model.RoleName; Secret = model.Secret; } public User(User user) { Id = user.Id; RoleName = user.RoleName; Role = user.Role; Name = user.Name; Secret = user.Secret; HashSecret = user.HashSecret; } [Key] public Guid Id { get; set; } = Guid.NewGuid(); [NotMapped] public string RoleName { get; set; } = null!; public IdentityPolicyNames Role { get { if (Enum.TryParse(RoleName, out var result)) return result; else return IdentityPolicyNames.NotSupport; } set => RoleName = Enum.GetName(value)!; } [StringLength(50)] public string Name { get; set; } = null!; [NotMapped] public string Secret { get; set; } = null!; public string HashSecret { get; set; } = null!; public object Clone() => new User(this); public IEnumerable GetUserClaims() => [new Claim(nameof(Name), Name), new Claim(ClaimTypes.Role, RoleName)]; } }