diff --git a/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs b/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs index 6a0f813..57dbaa8 100644 --- a/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs +++ b/DotBased.AspNet.Authority.EFCore/AuthorityContext.cs @@ -1,3 +1,4 @@ +using DotBased.AspNet.Authority.EFCore.Models; using DotBased.AspNet.Authority.Models.Authority; using Microsoft.EntityFrameworkCore; @@ -9,6 +10,10 @@ public class AuthorityContext(DbContextOptions options) : DbCo public DbSet Groups { get; set; } public DbSet Roles { get; set; } public DbSet Users { get; set; } + + public DbSet RoleGroup { get; set; } + public DbSet RoleUser { get; set; } + public DbSet UserGroup { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { @@ -29,6 +34,7 @@ public class AuthorityContext(DbContextOptions options) : DbCo { roleEntity.ToTable("authority_roles"); roleEntity.HasKey(x => x.Id); + roleEntity.HasMany(r => r.Attributes).WithOne().HasForeignKey(a => a.BoundId).OnDelete(DeleteBehavior.Cascade); }); modelBuilder.Entity(userEntity => @@ -37,6 +43,24 @@ public class AuthorityContext(DbContextOptions options) : DbCo userEntity.HasKey(x => x.Id); userEntity.HasMany(u => u.Attributes).WithOne().HasForeignKey(a => a.BoundId).OnDelete(DeleteBehavior.Cascade); }); + + modelBuilder.Entity(rgEntity => + { + rgEntity.ToTable("role_group"); + rgEntity.HasKey(rg => new { rg.RoleId, rg.GroupId }); + }); + + modelBuilder.Entity(ruEntity => + { + ruEntity.ToTable("role_user"); + ruEntity.HasKey(ru => new { ru.RoleId, ru.UserId }); + }); + + modelBuilder.Entity(ugEntity => + { + ugEntity.ToTable("user_group"); + ugEntity.HasKey(ug => new { ug.UserId, ug.GroupId }); + }); base.OnModelCreating(modelBuilder); } diff --git a/DotBased.AspNet.Authority.EFCore/Models/RoleGroup.cs b/DotBased.AspNet.Authority.EFCore/Models/RoleGroup.cs new file mode 100644 index 0000000..1afe9a7 --- /dev/null +++ b/DotBased.AspNet.Authority.EFCore/Models/RoleGroup.cs @@ -0,0 +1,7 @@ +namespace DotBased.AspNet.Authority.EFCore.Models; + +public class RoleGroup +{ + public Guid RoleId { get; set; } + public Guid GroupId { get; set; } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority.EFCore/Models/RoleUser.cs b/DotBased.AspNet.Authority.EFCore/Models/RoleUser.cs new file mode 100644 index 0000000..c4a0917 --- /dev/null +++ b/DotBased.AspNet.Authority.EFCore/Models/RoleUser.cs @@ -0,0 +1,7 @@ +namespace DotBased.AspNet.Authority.EFCore.Models; + +public class RoleUser +{ + public Guid RoleId { get; set; } + public Guid UserId { get; set; } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority.EFCore/Models/UserGroup.cs b/DotBased.AspNet.Authority.EFCore/Models/UserGroup.cs new file mode 100644 index 0000000..648b376 --- /dev/null +++ b/DotBased.AspNet.Authority.EFCore/Models/UserGroup.cs @@ -0,0 +1,7 @@ +namespace DotBased.AspNet.Authority.EFCore.Models; + +public class UserGroup +{ + public Guid UserId { get; set; } + public Guid GroupId { get; set; } +} \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs index 05f85c9..fdcae2f 100755 --- a/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityGroup.cs @@ -1,24 +1,18 @@ namespace DotBased.AspNet.Authority.Models.Authority; -public class AuthorityGroup +public class AuthorityGroup() { public AuthorityGroup(string name) : this() { Name = name; } - - public AuthorityGroup() - { - Id = Guid.NewGuid(); - CreatedDate = DateTime.Now; - } - - public Guid Id { get; set; } - + + public Guid Id { get; set; } = Guid.NewGuid(); + public string? Name { get; set; } public long Version { get; set; } - public DateTime CreatedDate { get; set; } + public DateTime CreatedDate { get; set; } = DateTime.Now; public ICollection Attributes { get; set; } = []; } \ No newline at end of file diff --git a/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs index 1e215aa..d3efc45 100755 --- a/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs +++ b/DotBased.AspNet.Authority/Models/Authority/AuthorityRole.cs @@ -15,5 +15,7 @@ public class AuthorityRole() public DateTime CreatedDate { get; set; } = DateTime.Now; + public IEnumerable Attributes { get; set; } = []; + public override string ToString() => Name ?? string.Empty; } \ No newline at end of file