This commit is contained in:
2025-08-28 16:01:55 +02:00
parent 68b74284c7
commit c7a94893a2
63 changed files with 633 additions and 200 deletions

View File

@@ -1,10 +1,17 @@
using MCVIngenieros.Transactional.Abstractions.Interfaces;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace back.DataModels;
public class RoleDto
{
public string Id { get; set; } = null!;
public List<PermissionDto> Permissions { get; set; } = [];
}
[Table("Roles")]
public partial class Role : IEquatable<Role>
public partial class Role : IEntity<Role>
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public string Id { get; set; } = null!;
@@ -18,7 +25,6 @@ public partial class Role : IEquatable<Role>
public virtual ICollection<Permission> Permissions { get; set; } = new HashSet<Permission>();
public virtual ICollection<User> Users { get; set; } = [];
public bool IsAdmin() => BaseRoleModel != null ? BaseRoleModel.IsAdmin() : Id == AdminRole.Id;
public bool IsContentManager() => BaseRoleModel != null ? BaseRoleModel.IsContentManager() : Id == ContentManagerRole.Id;
public bool IsUser() => BaseRoleModel != null ? BaseRoleModel.IsUser() : Id == UserRole.Id;
@@ -43,7 +49,7 @@ public partial class Role : IEquatable<Role>
BaseRoleModelId = baseRoleModel.Id;
foreach (var permission in baseRoleModel.Permissions)
{
if (!Permissions.Any(p => p.Id == permission.Id))
if (!Permissions.Any(p => p.Id == permission.Id))
{
Permissions.Add(permission);
}
@@ -62,6 +68,33 @@ public partial class Role : IEquatable<Role>
return Id == other.Id || GetHashCode() == other.GetHashCode();
}
public bool IsNull => this is null;
public object Clone() => (Role)MemberwiseClone();
public int CompareTo(object? obj)
{
if (obj is null) return 1;
if (obj is not Role other) throw new ArgumentException("Object is not a Person");
return CompareTo(other);
}
public int CompareTo(Role? other)
{
if (other is null) return 1;
if (ReferenceEquals(this, other)) return 0;
return string.Compare(Id, other.Id, StringComparison.OrdinalIgnoreCase);
}
public RoleDto ToDto()
{
return new RoleDto
{
Id = Id,
Permissions = [.. Permissions.Select(p => p.ToDto())]
};
}
public static readonly Role UserRole = new(
"1", "User", "Role for regular users",
[