diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj
index 221b629046209bf710c29a9d466a8b55e0daf096..a0e09d16f8cf6bdcacbb5f9ac8f7b1d4af3902ad 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdmin.DataAccess.EFCore.csproj
@@ -2,7 +2,8 @@
-
+
+
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs
index 7ba57af4cd1109d6c1739d252e094e2ca49f7266..71268bedfc4c4c18a2ec8261655a9c49d0f76e73 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs
@@ -1,49 +1,84 @@
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
-namespace BootstrapAdmin.DataAccess.EFCore;
-
-///
-///
-///
-public class BootstrapAdminContext : DbContext
+namespace BootstrapAdmin.DataAccess.EFCore
{
///
- /// 构造函数
+ ///
///
- ///
- public BootstrapAdminContext(DbContextOptions options) : base(options)
+ public class BootstrapAdminContext : DbContext
{
+ ///
+ /// 构造函数
+ ///
+ ///
+ public BootstrapAdminContext(DbContextOptions options) : base(options)
+ {
- }
+ }
- ///
- ///
- ///
- [NotNull]
- public DbSet? Dicts { get; set; }
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? Dicts { get; set; }
- ///
- ///
- ///
- [NotNull]
- public DbSet? Users { get; set; }
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? Users { get; set; }
- ///
- ///
- ///
- [NotNull]
- public DbSet? Navigations { get; set; }
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? Roles { get; set; }
- ///
- ///
- ///
- ///
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity().Ignore(u => u.Period);
- modelBuilder.Entity().Ignore(u => u.NewPassword);
- modelBuilder.Entity().Ignore(u => u.CofirmPassword);
- modelBuilder.Entity().Ignore(u => u.IsReset);
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? UserRole { get; set; }
+
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? Navigations { get; set; }
+
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? NavigationRole { get; set; }
+
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? Groups { get; set; }
+
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? UserGroup { get; set; }
+
+ ///
+ ///
+ ///
+ [NotNull]
+ public DbSet? RoleGroup { get; set; }
+
+ ///
+ ///
+ ///
+ ///
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ base.OnModelCreating(modelBuilder);
+ EntityConfiguration.Configure(modelBuilder);
+ }
}
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/EntityConfiguration.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/EntityConfiguration.cs
new file mode 100644
index 0000000000000000000000000000000000000000..8c9826695acbb207fe22689b2ebb0e1a65f5042a
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/EntityConfiguration.cs
@@ -0,0 +1,71 @@
+using BootstrapAdmin.DataAccess.Models;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.ChangeTracking;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+using Microsoft.EntityFrameworkCore.ValueGeneration;
+
+namespace BootstrapAdmin.DataAccess.EFCore;
+
+public static class EntityConfiguration
+{
+ ///
+ ///
+ ///
+ ///
+ public static void Configure(this ModelBuilder builder)
+ {
+ var converter = new ValueConverter(
+ v => Convert.ToInt32(v),
+ v => v.ToString(),
+ new ConverterMappingHints(valueGeneratorFactory: (p, t) => new GuidStringGenerator()));
+
+ builder.Entity().ToTable("Users");
+ builder.Entity().Ignore(u => u.Period);
+ builder.Entity().Ignore(u => u.NewPassword);
+ builder.Entity().Ignore(u => u.ConfirmPassword);
+ builder.Entity().Ignore(u => u.IsReset);
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+ builder.Entity().HasMany(s => s.Roles).WithMany(s => s.Users).UsingEntity(s =>
+ {
+ s.HasOne(s => s.User).WithMany(s => s.UserRoles).HasForeignKey(s => s.UserId);
+ s.HasOne(s => s.Role).WithMany(s => s.UserRoles).HasForeignKey(s => s.RoleId);
+ });
+ builder.Entity().HasMany(s => s.Groups).WithMany(s => s.Users).UsingEntity(s =>
+ {
+ s.HasOne(s => s.User).WithMany(s => s.UserGroup).HasForeignKey(s => s.UserId);
+ s.HasOne(s => s.Group).WithMany(s => s.UserGroup).HasForeignKey(s => s.GroupId);
+ });
+
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+
+ builder.Entity().ToTable("Roles");
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+ builder.Entity().HasMany(s => s.Navigations).WithMany(s => s.Roles).UsingEntity(s =>
+ {
+ s.HasOne(s => s.Navigation).WithMany(s => s.NavigationRoles).HasForeignKey(s => s.NavigationId);
+ s.HasOne(s => s.Role).WithMany(s => s.NavigationRoles).HasForeignKey(s => s.RoleId);
+ });
+ builder.Entity().HasMany(s => s.Groups).WithMany(s => s.Roles).UsingEntity(s =>
+ {
+ s.HasOne(s => s.Group).WithMany(s => s.RoleGroup).HasForeignKey(s => s.GroupId);
+ s.HasOne(s => s.Role).WithMany(s => s.RoleGroup).HasForeignKey(s => s.RoleId);
+ });
+
+ builder.Entity().ToTable("Navigations");
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+ builder.Entity().Ignore(s => s.HasChildren);
+
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+
+ builder.Entity().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
+ }
+}
+
+internal class GuidStringGenerator : ValueGenerator
+{
+
+ public override bool GeneratesTemporaryValues => false;
+
+ protected override object? NextValue(EntityEntry entry) => "0";
+
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs
index 78439a7c2a8d4ef364fc7773c772d9f866861160..b977005efd21472543a51c5b472e9b1dc6b1fd7e 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs
@@ -45,8 +45,12 @@ public static class ServicesExtensions
// 增加数据服务
services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>));
- services.AddSingleton();
- services.AddSingleton();
- return services;
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ services.AddSingleton();
+ return services;
+ }
}
-}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs
index a801c1e43b5c5584e3f2cda9fce17d267f23967e..44f40b8988dbc988d20cc621072c84a600a8eedd 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs
@@ -1,58 +1,109 @@
using BootstrapAdmin.DataAccess.Models;
using BootstrapAdmin.Web.Core;
using BootstrapBlazor.Components;
+using Longbow.Security.Cryptography;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
namespace BootstrapAdmin.DataAccess.EFCore.Services;
class DictService : IDict
{
- public List GetAll()
- {
- throw new NotImplementedException();
- }
+ private IDbContextFactory DbFactory { get; set; }
- public Dictionary GetApps()
- {
- throw new NotImplementedException();
- }
+ private string AppId { get; set; }
- public Dictionary GetLogins()
- {
- throw new NotImplementedException();
- }
+ ///
+ ///
+ ///
+ ///
+ ///
+ public DictService(IDbContextFactory factory, IConfiguration configuration)
+ {
+ DbFactory = factory;
+ AppId = configuration.GetValue("AppId", "BA");
+ }
- public Dictionary GetThemes()
- {
- throw new NotImplementedException();
- }
+ private List GetAll()
+ {
+ using var context = DbFactory.CreateDbContext();
+ return context.Dicts.ToList();
+ }
- public string GetWebFooter()
- {
- throw new NotImplementedException();
- }
+ public Dictionary GetApps()
+ {
+ var dicts = GetAll();
+ return dicts.Where(d => d.Category == "应用程序").Select(d => new KeyValuePair(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
+ }
- public string GetWebTitle()
- {
- throw new NotImplementedException();
- }
+ public Dictionary GetLogins()
+ {
+ var dicts = GetAll();
+ return dicts.Where(d => d.Category == "系统首页").Select(d => new KeyValuePair(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
+ }
- public bool IsDemo()
- {
- throw new NotImplementedException();
- }
+ public Dictionary GetThemes()
+ {
+ var dicts = GetAll();
+ return dicts.Where(d => d.Category == "网站样式").Select(d => new KeyValuePair(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
+ }
- public bool SaveDemo(bool isDemo)
- {
- throw new NotImplementedException();
- }
+ public string GetWebFooter()
+ {
+ var dicts = GetAll();
+ var title = "网站页脚";
+ var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
+ if (!string.IsNullOrEmpty(name))
+ {
+ var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚");
+ title = dict?.Code ?? "网站标题";
+ }
+ return title;
+ }
- public bool AuthenticateDemo(string code)
- {
- throw new NotImplementedException();
- }
+ public string GetWebTitle()
+ {
+ var dicts = GetAll();
+ var title = "网站标题";
+ var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name;
+ if (!string.IsNullOrEmpty(name))
+ {
+ var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题");
+ title = dict?.Code ?? "网站标题";
+ }
+ return title;
+ }
+
+ public bool IsDemo()
+ {
+ var dicts = GetAll();
+ var code = dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "演示系统" && d.Define == EnumDictDefine.System)?.Code ?? "0";
+ return code == "1";
+ }
+
+ public bool SaveDemo(bool isDemo)
+ {
+ throw new NotImplementedException();
+ }
+
+ public bool AuthenticateDemo(string code)
+ {
+ var ret = false;
+ if (!string.IsNullOrEmpty(code))
+ {
+ var dicts = GetAll();
+ var salt = dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "授权盐值" && d.Define == EnumDictDefine.System)?.Code;
+ var authCode = dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "哈希结果" && d.Define == EnumDictDefine.System)?.Code;
+ if (!string.IsNullOrEmpty(salt))
+ {
+ ret = LgbCryptography.ComputeHash(code, salt) == authCode;
+ }
+ }
+ return ret;
+ }
- public bool SaveHealthCheck(bool enable = true)
- {
- throw new NotImplementedException();
+ public bool SaveHealthCheck(bool enable = true)
+ {
+ return true;
+ }
}
-}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/GroupService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/GroupService.cs
new file mode 100644
index 0000000000000000000000000000000000000000..0565379c0d453221c5f1de57a62a28202f74d350
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/GroupService.cs
@@ -0,0 +1,68 @@
+using BootstrapAdmin.DataAccess.Models;
+using BootstrapAdmin.Web.Core;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.EFCore.Services;
+
+public class GroupService : IGroup
+{
+ private IDbContextFactory DbFactory;
+
+ public GroupService(IDbContextFactory dbFactory) => DbFactory = dbFactory;
+
+ public List GetAll()
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.Groups.ToList();
+ }
+
+ public List GetGroupsByRoleId(string? roleId)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.RoleGroup.Where(s => s.RoleId == roleId).Select(s => s.GroupId!).ToList();
+ }
+
+ public List GetGroupsByUserId(string? userId)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.UserGroup.Where(s => s.UserId == userId).Select(s => s.GroupId!).ToList();
+ }
+
+ public bool SaveGroupsByRoleId(string? roleId, IEnumerable groupIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var role = dbcontext.Roles.Include(s => s.Groups).Where(s => s.Id == roleId).FirstOrDefault();
+ if (role != null)
+ {
+ role.Groups = dbcontext.Groups.Where(s => groupIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool SaveGroupsByUserId(string? userId, IEnumerable groupIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var user = dbcontext.Users.Include(s => s.Groups).Where(s => s.Id == userId).FirstOrDefault();
+ if (user != null)
+ {
+ user.Groups = dbcontext.Groups.Where(s => groupIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/LoginService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/LoginService.cs
new file mode 100644
index 0000000000000000000000000000000000000000..9d006d7066ecc19e27caf4c4926554ba18d3d66d
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/LoginService.cs
@@ -0,0 +1,16 @@
+using BootstrapAdmin.Web.Core;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.EFCore.Services;
+
+public class LoginService : ILogin
+{
+ public Task Log(string userName, bool result)
+ {
+ return Task.FromResult(true);
+ }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs
index 1e4b9903a726f65b84f31b42db5832d504e75257..ef24026d252623371d9cd4b147fe1f1aedb0d1e4 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs
@@ -2,40 +2,57 @@
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
-namespace BootstrapAdmin.DataAccess.EFCore.Services;
-
-///
-///
-///
-class NavigationsService : INavigation
+namespace BootstrapAdmin.DataAccess.EFCore.Services
{
- private IDbContextFactory DbFactory { get; set; }
-
///
///
///
- ///
- public NavigationsService(IDbContextFactory factory) => DbFactory = factory;
-
- ///
- /// 获得指定用户名可访问的所有菜单集合
- ///
- /// 当前用户名
- /// 未层次化的菜单集合
- public List GetAllMenus(string userName)
+ class NavigationsService : INavigation
{
- using var context = DbFactory.CreateDbContext();
- //return context..Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID", new { UserName = userName, Category = "菜单", RoleName = "Administrators" });
- return new List();
- }
+ private IDbContextFactory DbFactory { get; set; }
- public List GetMenusByRoleId(string? roleId)
- {
- throw new NotImplementedException();
- }
+ ///
+ ///
+ ///
+ ///
+ public NavigationsService(IDbContextFactory factory) => DbFactory = factory;
- public bool SaveMenusByRoleId(string? roleId, List menuIds)
- {
- throw new NotImplementedException();
+ ///
+ /// 获得指定用户名可访问的所有菜单集合
+ ///
+ /// 当前用户名
+ /// 未层次化的菜单集合
+ public List GetAllMenus(string userName)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ var user = context.Set().Include(s => s.Roles!).ThenInclude(s => s.Navigations!.Where(s => s.IsResource == EnumResource.Navigation)).AsSplitQuery().FirstOrDefault(s => s.UserName == userName);
+
+ if (user == null)
+ return new List();
+ return user.Roles!.SelectMany(s => s.Navigations!).ToList();
+ }
+
+ public List GetMenusByRoleId(string? roleId)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ return context.NavigationRole.Where(s => s.RoleId == roleId).Select(s => s.NavigationId!).ToList();
+ }
+
+ public bool SaveMenusByRoleId(string? roleId, List menuIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var currentrole = dbcontext.Roles.Include(s => s.Navigations).Where(s => s.Id == roleId).FirstOrDefault();
+ if (currentrole != null)
+ {
+ currentrole.Navigations = dbcontext.Navigations.Where(s => menuIds.Contains(s.Id!)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
}
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/RoleService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/RoleService.cs
new file mode 100644
index 0000000000000000000000000000000000000000..a8feff7674e391c669230287760e3f52db0a1660
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/RoleService.cs
@@ -0,0 +1,90 @@
+using BootstrapAdmin.DataAccess.Models;
+using BootstrapAdmin.Web.Core;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.EFCore.Services;
+
+public class RoleService : IRole
+{
+ private IDbContextFactory DbFactory;
+
+ public RoleService(IDbContextFactory dbFactory) => DbFactory = dbFactory;
+
+ public List GetAll()
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.Roles.ToList();
+ }
+
+ public List GetRolesByGroupId(string? groupId)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.RoleGroup.Where(s => s.GroupId == groupId).Select(s => s.RoleId!).ToList();
+ }
+
+ public List GetRolesByMenuId(string? menuId)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.NavigationRole.Where(s => s.NavigationId == menuId).Select(s => s.RoleId!).ToList();
+ }
+
+ public List GetRolesByUserId(string? userId)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+
+ return dbcontext.UserRole.Where(s => s.UserId == userId).Select(s => s.RoleId!).ToList();
+ }
+
+ public bool SaveRolesByGroupId(string? groupId, IEnumerable roleIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var group = dbcontext.Groups.Include(s => s.Roles).Where(s => s.Id == groupId).FirstOrDefault();
+ if (group != null)
+ {
+ group.Roles = dbcontext.Roles.Where(s => roleIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool SaveRolesByMenuId(string? menuId, IEnumerable roleIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var menu = dbcontext.Navigations.Include(s => s.Roles).Where(s => s.Id == menuId).FirstOrDefault();
+ if (menu != null)
+ {
+ menu.Roles = dbcontext.Roles.Where(s => roleIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool SaveRolesByUserId(string? userId, IEnumerable roleIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var user = dbcontext.Users.Include(s => s.Roles).Where(s => s.Id == userId).FirstOrDefault();
+ if (user != null)
+ {
+ user.Roles = dbcontext.Roles.Where(s => roleIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/UserService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/UserService.cs
new file mode 100644
index 0000000000000000000000000000000000000000..05a0e560735b1f5a34052bc8fed836b7e7c66f4f
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/UserService.cs
@@ -0,0 +1,139 @@
+using BootstrapAdmin.DataAccess.Models;
+using BootstrapAdmin.Web.Core;
+using Longbow.Security.Cryptography;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.EFCore.Services;
+
+public class UserService : IUser
+{
+ private IDbContextFactory DbFactory { get; set; }
+
+ public UserService(IDbContextFactory factory) => DbFactory = factory;
+
+ public List GetAll()
+ {
+ using var context = DbFactory.CreateDbContext();
+ return context.Users.ToList();
+ }
+
+ public bool Authenticate(string userName, string password)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ var user = context.Users.Where(s => s.ApprovedTime != null).FirstOrDefault(x => x.UserName == userName);
+
+ var isAuth = false;
+ if (user != null && !string.IsNullOrEmpty(user.PassSalt))
+ {
+ isAuth = user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
+ }
+ return isAuth;
+ }
+
+ public List GetApps(string userName)
+ {
+ return new List { "BA" };
+ }
+
+ public string? GetDisplayName(string? userName)
+ {
+ using var context = DbFactory.CreateDbContext();
+ return string.IsNullOrEmpty(userName) ? "" : context.Users.FirstOrDefault(s => s.UserName == userName)?.DisplayName;
+ }
+
+ public List GetRoles(string userName)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ var user = context.Users.Include(s => s.Roles).FirstOrDefault(s => s.UserName == userName);
+
+ return user != null ? user.Roles!.Select(s => s.RoleName).ToList() : new List();
+ }
+
+ public List GetUsersByGroupId(string? groupId)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ return context.UserGroup.Where(s => s.GroupId == groupId).Select(s => s.UserId!).ToList();
+ }
+
+ public List GetUsersByRoleId(string? roleId)
+ {
+ using var context = DbFactory.CreateDbContext();
+
+ return context.UserRole.Where(s => s.RoleId == roleId).Select(s => s.UserId!).ToList();
+ }
+
+ public bool SaveUsersByGroupId(string? groupId, IEnumerable userIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var group = dbcontext.Groups.Include(s => s.Users).Where(s => s.Id == groupId).FirstOrDefault();
+ if (group != null)
+ {
+ group.Users = dbcontext.Users.Where(s => userIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool SaveUsersByRoleId(string? roleId, IEnumerable userIds)
+ {
+ using var dbcontext = DbFactory.CreateDbContext();
+ var currentrole = dbcontext.Roles.Include(s => s.Users).Where(s => s.Id == roleId).FirstOrDefault();
+ if (currentrole != null)
+ {
+ currentrole.Users = dbcontext.Users.Where(s => userIds.Contains(s.Id)).ToList();
+ return dbcontext.SaveChanges() > 0;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ public bool TryCreateUserByPhone(string phone, string appId, ICollection roles)
+ {
+ var ret = false;
+ using var dbcontext = DbFactory.CreateDbContext();
+ try
+ {
+ var user = GetAll().FirstOrDefault(user => user.UserName == phone);
+ if (user == null)
+ {
+ dbcontext.Database.BeginTransaction();
+ user = new User()
+ {
+ ApprovedBy = "Mobile",
+ ApprovedTime = DateTime.Now,
+ DisplayName = "手机用户",
+ UserName = phone,
+ Icon = "default.jpg",
+ Description = "手机用户",
+ App = appId
+ };
+ dbcontext.Add(user);
+
+ // Authorization
+ var roleIds = dbcontext.Roles.Where(s => roles.Contains(s.RoleName)).Select(s => s.Id).ToList();
+ dbcontext.AddRange(roleIds.Select(g => new { RoleID = g, UserID = user.Id }));
+ ret = dbcontext.SaveChanges() > 0;
+ }
+ ret = true;
+ }
+ catch (Exception)
+ {
+
+ throw;
+ }
+ return ret;
+ }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs
index 6b3fb959e7272cfafec2a401e2c4388408045558..c410bf13dceedf3f234ef1a8c057b19c0801dddc 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs
@@ -1,32 +1,33 @@
using System.ComponentModel;
-namespace BootstrapAdmin.DataAccess.Models;
-
-///
-/// 后台数据库脚本执行日志实体类
-///
-public class DBLog
+namespace BootstrapAdmin.DataAccess.Models
{
///
- /// 获得/设置 主键ID
+ /// 后台数据库脚本执行日志实体类
///
- public string? Id { get; set; }
+ public class DBLog
+ {
+ ///
+ /// 获得/设置 主键ID
+ ///
+ public string? Id { get; set; }
- ///
- /// 获得/设置 当前登陆名
- ///
- [DisplayName("所属用户")]
- public string? UserName { get; set; }
+ ///
+ /// 获得/设置 当前登陆名
+ ///
+ [DisplayName("所属用户")]
+ public string? UserName { get; set; }
- ///
- /// 获得/设置 数据库执行脚本
- ///
- [DisplayName("脚本内容")]
- public string SQL { get; set; } = "";
+ ///
+ /// 获得/设置 数据库执行脚本
+ ///
+ [DisplayName("脚本内容")]
+ public string SQL { get; set; } = "";
- ///
- /// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
- ///
- [DisplayName("执行时间")]
- public DateTime LogTime { get; set; }
+ ///
+ /// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
+ ///
+ [DisplayName("执行时间")]
+ public DateTime LogTime { get; set; }
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs
index 08f5b38777a9b7a2ed144022c120228672bfd41c..3b1d10d576c5aadd3a7d3dc4a18b32048497905e 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs
@@ -1,36 +1,57 @@
using System.ComponentModel.DataAnnotations;
-namespace BootstrapAdmin.DataAccess.Models;
-
-///
-/// Group 实体类
-///
-public class Group
+namespace BootstrapAdmin.DataAccess.Models
{
///
- /// 获得/设置 主键 ID
+ /// Group 实体类
///
- public string? Id { get; set; }
+ public class Group
+ {
+ ///
+ /// 获得/设置 主键 ID
+ ///
+ public string? Id { get; set; }
- ///
- /// 获得/设置 群组名称
- ///
- [Display(Name = "群组名称")]
- [NotNull]
- public string? GroupName { get; set; }
+ ///
+ /// 获得/设置 群组名称
+ ///
+ [Display(Name = "群组名称")]
+ [NotNull]
+ public string? GroupName { get; set; }
- ///
- /// 获得/设置 群组编码
- ///
- [Display(Name = "群组编码")]
- [NotNull]
- public string? GroupCode { get; set; }
+ ///
+ /// 获得/设置 群组编码
+ ///
+ [Display(Name = "群组编码")]
+ [NotNull]
+ public string? GroupCode { get; set; }
- ///
- /// 获得/设置 群组描述
- ///
- [Display(Name = "群组描述")]
- public string? Description { get; set; }
+ ///
+ /// 获得/设置 群组描述
+ ///
+ [Display(Name = "群组描述")]
+ public string? Description { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Users { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? UserGroup { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Roles { get; set; }
+
+ ///
+ ///
+ ///
+ public List? RoleGroup { get; set; }
- public override string ToString() => $"{GroupName} ({GroupCode})";
+ public override string ToString() => $"{GroupName} ({GroupCode})";
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs
index c302aaa6049220dacc2c58b799a6b79dd23f10de..0528f1317c711b343be9200bf8e1186e5d312922 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs
@@ -2,75 +2,86 @@
using System.ComponentModel.DataAnnotations;
-namespace BootstrapAdmin.DataAccess.Models;
-
-///
-/// Bootstrap Admin 后台管理菜单相关操作实体类
-///
-public class Navigation
+namespace BootstrapAdmin.DataAccess.Models
{
///
- /// 获得/设置 菜单主键ID
+ /// Bootstrap Admin 后台管理菜单相关操作实体类
///
- public string? Id { set; get; }
+ public class Navigation
+ {
+ ///
+ /// 获得/设置 菜单主键ID
+ ///
+ public string? Id { set; get; }
- ///
- /// 获得/设置 父级菜单ID 默认为 0
- ///
- public string ParentId { set; get; } = "0";
+ ///
+ /// 获得/设置 父级菜单ID 默认为 0
+ ///
+ public string ParentId { set; get; } = "0";
- ///
- /// 获得/设置 菜单名称
- ///
- [Display(Name = "名称")]
- [NotNull]
- public string? Name { get; set; }
+ ///
+ /// 获得/设置 菜单名称
+ ///
+ [Display(Name = "名称")]
+ [NotNull]
+ public string? Name { get; set; }
- ///
- /// 获得/设置 菜单序号
- ///
- [Display(Name = "序号")]
- public int Order { get; set; }
+ ///
+ /// 获得/设置 菜单序号
+ ///
+ [Display(Name = "序号")]
+ public int Order { get; set; }
- ///
- /// 获得/设置 菜单图标
- ///
- [Display(Name = "图标")]
- public string? Icon { get; set; }
+ ///
+ /// 获得/设置 菜单图标
+ ///
+ [Display(Name = "图标")]
+ public string? Icon { get; set; }
- ///
- /// 获得/设置 菜单URL地址
- ///
- [NotNull]
- [Display(Name = "地址")]
- public string? Url { get; set; }
+ ///
+ /// 获得/设置 菜单URL地址
+ ///
+ [NotNull]
+ [Display(Name = "地址")]
+ public string? Url { get; set; }
- ///
- /// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
- ///
- [Display(Name = "类别")]
- public EnumNavigationCategory Category { get; set; }
+ ///
+ /// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
+ ///
+ [Display(Name = "类别")]
+ public EnumNavigationCategory Category { get; set; }
- ///
- /// 获得/设置 链接目标
- ///
- [Display(Name = "目标")]
- public string? Target { get; set; }
+ ///
+ /// 获得/设置 链接目标
+ ///
+ [Display(Name = "目标")]
+ public string? Target { get; set; }
- ///
- /// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
- ///
- [Display(Name = "类型")]
- public EnumResource IsResource { get; set; }
+ ///
+ /// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
+ ///
+ [Display(Name = "类型")]
+ public EnumResource IsResource { get; set; }
- ///
- /// 获得/设置 所属应用程序,此属性由BA后台字典表分配
- ///
- [Display(Name = "所属应用")]
- public string? Application { get; set; }
+ ///
+ /// 获得/设置 所属应用程序,此属性由BA后台字典表分配
+ ///
+ [Display(Name = "所属应用")]
+ public string? Application { get; set; }
- ///
- ///
- ///
- public bool HasChildren { get; set; }
+ ///
+ ///
+ ///
+ public bool HasChildren { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Roles { get; set; }
+
+ ///
+ ///
+ ///
+ public List? NavigationRoles { get; set; }
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/NavigationRole.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/NavigationRole.cs
new file mode 100644
index 0000000000000000000000000000000000000000..2a306c15a4c30b9049e8225815ba88ba2f6ee35d
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/NavigationRole.cs
@@ -0,0 +1,29 @@
+namespace BootstrapAdmin.DataAccess.Models;
+
+public class NavigationRole
+{
+ ///
+ ///
+ ///
+ public string? Id { get; set; }
+
+ ///
+ ///
+ ///
+ public string? NavigationId { get; set; }
+
+ ///
+ ///
+ ///
+ public Navigation? Navigation { get; set; }
+
+ ///
+ ///
+ ///
+ public string? RoleId { get; set; }
+
+ ///
+ ///
+ ///
+ public Role? Role { get; set; }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs
index ce6b65f66c76fd184ad047c5d66ef54bcd63273e..ccd566e7ff5eef0dc0c876111584e3705c725547 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs
@@ -1,29 +1,61 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
-namespace BootstrapAdmin.DataAccess.Models;
-
-///
-/// Role 实体类
-///
-public class Role
+namespace BootstrapAdmin.DataAccess.Models
{
///
- /// 获得/设置 角色主键ID
+ /// Role 实体类
///
- public string? Id { get; set; }
+ public class Role
+ {
+ ///
+ /// 获得/设置 角色主键ID
+ ///
+ public string? Id { get; set; }
- ///
- /// 获得/设置 角色名称
- ///
- [DisplayName("角色名称")]
- [NotNull]
- public string? RoleName { get; set; }
+ ///
+ /// 获得/设置 角色名称
+ ///
+ [DisplayName("角色名称")]
+ [NotNull]
+ public string? RoleName { get; set; }
- ///
- /// 获得/设置 角色描述
- ///
- [DisplayName("角色描述")]
- [NotNull]
- public string? Description { get; set; }
+ ///
+ /// 获得/设置 角色描述
+ ///
+ [DisplayName("角色描述")]
+ [NotNull]
+ public string? Description { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Users { get; set; }
+
+ ///
+ ///
+ ///
+ public List? UserRoles { get; set; }
+
+
+ ///
+ ///
+ ///
+ public ICollection? Navigations { get; set; }
+
+ ///
+ ///
+ ///
+ public List? NavigationRoles { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Groups { get; set; }
+
+ ///
+ ///
+ ///
+ public List? RoleGroup { get; set; }
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/RoleGroup.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/RoleGroup.cs
new file mode 100644
index 0000000000000000000000000000000000000000..4bf58b04e4455b21a2e9564b3d7c477f55e3bf6c
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/RoleGroup.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.Models;
+
+public class RoleGroup
+{
+ public string? Id { get; set; }
+
+ public string? RoleId { get; set; }
+
+ public Role? Role { get; set; }
+
+ public string? GroupId { get; set; }
+
+ public Group? Group { get; set; }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs
index 54f22a9e41001282194ac8c81848fe22a823c212..3f95ed8f66f8e706390a2cb13b34072793f236bd 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs
@@ -1,151 +1,172 @@
using System.ComponentModel.DataAnnotations;
-namespace BootstrapAdmin.DataAccess.Models;
-
-///
-///
-///
-public class User
-{
- ///
- /// 获得/设置 系统登录用户名
- ///
- [Display(Name = "登录名称")]
- public string? UserName { get; set; }
-
- ///
- /// 获得/设置 用户显示名称
- ///
- [Display(Name = "显示名称")]
- [Required(ErrorMessage = "{0}不可为空")]
- [MaxLength(50, ErrorMessage = "{0}不能超过 50 个字符")]
- public string? DisplayName { get; set; }
-
- ///
- /// 获得/设置 用户头像图标路径
- ///
- [Display(Name = "用户头像")]
- public string? Icon { get; set; }
-
- ///
- /// 获得/设置 用户设置样式表名称
- ///
- [Display(Name = "主题")]
- public string? Css { get; set; }
-
- ///
- /// 获得/设置 用户默认登陆 App 标识
- ///
- [Display(Name = "默认 APP")]
- public string? App { get; set; }
-
- ///
- /// 获得/设置 用户主键ID
- ///
- public string? Id { get; set; }
-
- ///
- /// 获取/设置 密码
- ///
- [Display(Name = "密码")]
- [Required(ErrorMessage = "{0}不可为空")]
- public string? Password { get; set; }
-
- ///
- /// 获取/设置 密码盐
- ///
- public string? PassSalt { get; set; }
-
- ///
- /// 获得/设置 用户注册时间
- ///
- [Display(Name = "注册时间")]
- public DateTime RegisterTime { get; set; } = DateTime.Now;
-
- ///
- /// 获得/设置 用户被批复时间
- ///
- [Display(Name = "授权时间")]
- public DateTime? ApprovedTime { get; set; }
-
- ///
- /// 获得/设置 用户批复人
- ///
- [Display(Name = "授权人")]
- public string? ApprovedBy { get; set; }
-
- ///
- /// 获得/设置 用户的申请理由
- ///
- [Display(Name = "说明")]
- public string? Description { get; set; }
-
- ///
- /// 获得/设置 通知描述 2分钟内为刚刚
- ///
- public string? Period { get; set; }
-
- ///
- /// 获得/设置 新密码
- ///
- [Display(Name = "新密码")]
- [Required(ErrorMessage = "{0}不可为空")]
- [NotNull]
- public string? NewPassword { get; set; }
-
- ///
- /// 获得/设置 新密码
- ///
- [Display(Name = "确认密码")]
- [Required(ErrorMessage = "{0}不可为空")]
- [Compare("NewPassword", ErrorMessage = "{0}与{1}不一致")]
- [NotNull]
- public string? ConfirmPassword { get; set; }
-
- ///
- /// 获得/设置 是否重置密码
- ///
- public int IsReset { get; set; }
-
- ///
- /// 获得/设置 默认格式为 DisplayName (UserName)
- ///
- ///
- public override string ToString() => $"{DisplayName} ({UserName})";
-}
-
-///
-/// 用户状态枚举类型
-///
-public enum UserStates
+namespace BootstrapAdmin.DataAccess.Models
{
///
- /// 更改密码
- ///
- ChangePassword,
-
- ///
- /// 更改样式
- ///
- ChangeTheme,
-
- ///
- /// 更改显示名称
- ///
- ChangeDisplayName,
-
- ///
- /// 审批用户
- ///
- ApproveUser,
-
- ///
- /// 拒绝用户
- ///
- RejectUser,
-
- ///
- /// 保存默认应用
- ///
- SaveApp
+ ///
+ ///
+ public class User
+ {
+ ///
+ /// 获得/设置 系统登录用户名
+ ///
+ [Display(Name = "登录名称")]
+ public string? UserName { get; set; }
+
+ ///
+ /// 获得/设置 用户显示名称
+ ///
+ [Display(Name = "显示名称")]
+ [Required(ErrorMessage = "{0}不可为空")]
+ [MaxLength(50, ErrorMessage = "{0}不能超过 50 个字符")]
+ public string? DisplayName { get; set; }
+
+ ///
+ /// 获得/设置 用户头像图标路径
+ ///
+ [Display(Name = "用户头像")]
+ public string? Icon { get; set; }
+
+ ///
+ /// 获得/设置 用户设置样式表名称
+ ///
+ [Display(Name = "主题")]
+ public string? Css { get; set; }
+
+ ///
+ /// 获得/设置 用户默认登陆 App 标识
+ ///
+ [Display(Name = "默认 APP")]
+ public string? App { get; set; }
+
+ ///
+ /// 获得/设置 用户主键ID
+ ///
+ public string? Id { get; set; }
+
+ ///
+ /// 获取/设置 密码
+ ///
+ [Display(Name = "密码")]
+ [Required(ErrorMessage = "{0}不可为空")]
+ public string? Password { get; set; }
+
+ ///
+ /// 获取/设置 密码盐
+ ///
+ public string? PassSalt { get; set; }
+
+ ///
+ /// 获得/设置 用户注册时间
+ ///
+ [Display(Name = "注册时间")]
+ public DateTime RegisterTime { get; set; } = DateTime.Now;
+
+ ///
+ /// 获得/设置 用户被批复时间
+ ///
+ [Display(Name = "授权时间")]
+ public DateTime? ApprovedTime { get; set; }
+
+ ///
+ /// 获得/设置 用户批复人
+ ///
+ [Display(Name = "授权人")]
+ public string? ApprovedBy { get; set; }
+
+ ///
+ /// 获得/设置 用户的申请理由
+ ///
+ [Display(Name = "说明")]
+ public string? Description { get; set; }
+
+ ///
+ /// 获得/设置 通知描述 2分钟内为刚刚
+ ///
+ public string? Period { get; set; }
+
+ ///
+ /// 获得/设置 新密码
+ ///
+ [Display(Name = "新密码")]
+ [Required(ErrorMessage = "{0}不可为空")]
+ [NotNull]
+ public string? NewPassword { get; set; }
+
+ ///
+ /// 获得/设置 新密码
+ ///
+ [Display(Name = "确认密码")]
+ [Required(ErrorMessage = "{0}不可为空")]
+ [Compare("NewPassword", ErrorMessage = "{0}与{1}不一致")]
+ [NotNull]
+ public string? ConfirmPassword { get; set; }
+
+ ///
+ /// 获得/设置 是否重置密码
+ ///
+ public int IsReset { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Roles { get; set; }
+
+ ///
+ ///
+ ///
+ public List? UserRoles { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? Groups { get; set; }
+
+ ///
+ ///
+ ///
+ public ICollection? UserGroup { get; set; }
+
+ ///
+ /// 获得/设置 默认格式为 DisplayName (UserName)
+ ///
+ ///
+ public override string ToString() => $"{DisplayName} ({UserName})";
+ }
+
+ ///
+ /// 用户状态枚举类型
+ ///
+ public enum UserStates
+ {
+ ///
+ /// 更改密码
+ ///
+ ChangePassword,
+
+ ///
+ /// 更改样式
+ ///
+ ChangeTheme,
+
+ ///
+ /// 更改显示名称
+ ///
+ ChangeDisplayName,
+
+ ///
+ /// 审批用户
+ ///
+ ApproveUser,
+
+ ///
+ /// 拒绝用户
+ ///
+ RejectUser,
+
+ ///
+ /// 保存默认应用
+ ///
+ SaveApp
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserGroup.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserGroup.cs
new file mode 100644
index 0000000000000000000000000000000000000000..c1dcf576f6c0b4bc4b8aa9d805906a559142153b
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserGroup.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BootstrapAdmin.DataAccess.Models;
+
+public class UserGroup
+{
+ ///
+ ///
+ ///
+ public string? Id { get; set; }
+
+ ///
+ ///
+ ///
+ public string? UserId { get; set; }
+
+ ///
+ ///
+ ///
+ public User? User { get; set; }
+
+ ///
+ ///
+ ///
+ public string? GroupId { get; set; }
+
+ ///
+ ///
+ ///
+ public Group? Group { get; set; }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserRole.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserRole.cs
new file mode 100644
index 0000000000000000000000000000000000000000..8e5ac2070a8d4bf021c520e91fafbf8952ed3c37
--- /dev/null
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/UserRole.cs
@@ -0,0 +1,29 @@
+namespace BootstrapAdmin.DataAccess.Models;
+
+public class UserRole
+{
+ ///
+ ///
+ ///
+ public string? Id { get; set; }
+
+ ///
+ ///
+ ///
+ public string? UserId { get; set; }
+
+ ///
+ ///
+ ///
+ public User? User { get; set; }
+
+ ///
+ ///
+ ///
+ public string? RoleId { get; set; }
+
+ ///
+ ///
+ ///
+ public Role? Role { get; set; }
+}
diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs
index af7bf38369cf7aa3843dbf79442e055b753f1762..a8029656354ac39cf6fff086d68577223bf14810 100644
--- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs
+++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs
@@ -11,6 +11,11 @@ class DictService : BaseDatabase, IDict
{
private string AppId { get; set; }
+ ///
+ ///
+ ///
+ ///
+ ///
public DictService(IDatabase db, IConfiguration configuration)
{
Database = db;
@@ -108,7 +113,7 @@ class DictService : BaseDatabase, IDict
///
///
///
- public bool SaveDemo(bool isDemo) => Database.Execute("Update Dicts Set Code = @0 Where Category = @1 and Name = @2 and Define = @3", isDemo ? "1" : "0", "网站设置", "演示系统", EnumDictDefine.System) == 1;
+ public bool SaveDemo(bool isDemo) => Database.Execute("Update Dicts Set Code = @0 Where Category = @1 and Name = @2 and Define = @3", isDemo ? "1" : "0", "网站设置", "演示系统", EnumDictDefine.System.ToString()) == 1;
///
///
@@ -116,5 +121,5 @@ class DictService : BaseDatabase, IDict
///
///
///
- public bool SaveHealthCheck(bool enable = true) => Database.Execute("Update Dicts Set Code = @0 Where Category = @1 and Name = @2 and Define = @3", enable ? "1" : "0", "网站设置", "健康检查", EnumDictDefine.System) == 1;
+ public bool SaveHealthCheck(bool enable = true) => Database.Execute("Update Dicts Set Code = @0 Where Category = @1 and Name = @2 and Define = @3", enable ? "1" : "0", "网站设置", "健康检查", EnumDictDefine.System.ToString()) == 1;
}
diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs
index 496b973a5b37f36db3d17056f6c8627913a2a02a..a627b2080c305b27072a03caa10577ca6e130f22 100644
--- a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs
+++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs
@@ -1,71 +1,73 @@
using BootstrapAdmin.DataAccess.Models;
-namespace BootstrapAdmin.Web.Core;
-
-///
-/// Dict 字典表接口
-///
-public interface IDict
+namespace BootstrapAdmin.Web.Core
{
///
- /// 获得 所有数据方法
+ /// Dict 字典表接口
///
- ///
- List GetAll();
+ public interface IDict
+ {
- ///
- /// 获得 配置所有的 App 集合
- ///
- ///
- Dictionary GetApps();
+ ///
+ ///
+ ///
+ ///
+ List GetAll();
- ///
- /// 获得 配置所有的登录页集合
- ///
- ///
- Dictionary GetLogins();
+ ///
+ /// 获得 配置所有的 App 集合
+ ///
+ ///
+ Dictionary GetApps();
- ///
- /// 获得 配置所有的主题集合
- ///
- ///
- Dictionary GetThemes();
+ ///
+ /// 获得 配置所有的登录页集合
+ ///
+ ///
+ Dictionary GetLogins();
- ///
- /// 获取当前系统配置是否为演示模式
- ///
- ///
- bool IsDemo();
+ ///
+ /// 获得 配置所有的主题集合
+ ///
+ ///
+ Dictionary GetThemes();
- ///
- /// 保存当前网站是否为演示系统
- ///
- ///
- ///
- bool SaveDemo(bool isDemo);
+ ///
+ /// 获取当前系统配置是否为演示模式
+ ///
+ ///
+ bool IsDemo();
- ///
- /// 保存健康检查
- ///
- ///
- bool SaveHealthCheck(bool enable = true);
+ ///
+ /// 保存当前网站是否为演示系统
+ ///
+ ///
+ ///
+ bool SaveDemo(bool isDemo);
- ///
- /// 获得当前授权码是否有效可更改网站设置
- ///
- ///
- ///
- bool AuthenticateDemo(string code);
+ ///
+ /// 保存健康检查
+ ///
+ ///
+ bool SaveHealthCheck(bool enable = true);
- ///
- /// 获取 站点 Title 配置信息
- ///
- ///
- string GetWebTitle();
+ ///
+ /// 获得当前授权码是否有效可更改网站设置
+ ///
+ ///
+ ///
+ bool AuthenticateDemo(string code);
- ///
- /// 获取站点 Footer 配置信息
- ///
- ///
- string GetWebFooter();
+ ///
+ /// 获取 站点 Title 配置信息
+ ///
+ ///
+ string GetWebTitle();
+
+ ///
+ /// 获取站点 Footer 配置信息
+ ///
+ ///
+ string GetWebFooter();
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs
index ec9d32061e736a6539132908fe56a57376a2398e..27b2961ba72a1bdcfa38f29e12d116f8ea257acb 100644
--- a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs
+++ b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs
@@ -1,29 +1,30 @@
using BootstrapAdmin.DataAccess.Models;
-namespace BootstrapAdmin.Web.Core;
-
-///
-///
-///
-public interface INavigation
+namespace BootstrapAdmin.Web.Core
{
///
///
///
- ///
- List GetAllMenus(string userName);
+ public interface INavigation
+ {
+ ///
+ ///
+ ///
+ ///
+ List GetAllMenus(string userName);
- ///
- ///
- ///
- ///
- ///
- List GetMenusByRoleId(string? roleId);
+ ///
+ ///
+ ///
+ ///
+ ///
+ List GetMenusByRoleId(string? roleId);
- ///
- ///
- ///
- ///
- ///
- bool SaveMenusByRoleId(string? roleId, List menuIds);
+ ///
+ ///
+ ///
+ ///
+ ///
+ bool SaveMenusByRoleId(string? roleId, List menuIds);
+ }
}
diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IRole.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IRole.cs
index ad402b38dcacc72621fd7d956c395fa5af27dc3a..fef82be508584e19b187d1293101cb6ecc02fb61 100644
--- a/src/blazor/admin/BootstrapAdmin.Web.Core/IRole.cs
+++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IRole.cs
@@ -16,9 +16,9 @@ public interface IRole
///
///
///
- ///
+ ///
///
- List GetRolesByGroupId(string? userId);
+ List GetRolesByGroupId(string? groupId);
///
///
@@ -31,17 +31,17 @@ public interface IRole
///
///
///
- ///
+ ///
///
- List GetRolesByUserId(string? groupId);
+ List GetRolesByUserId(string? userId);
///
///
///
- ///
+ ///
///
///
- bool SaveRolesByUserId(string? groupId, IEnumerable roleIds);
+ bool SaveRolesByUserId(string? userId, IEnumerable roleIds);
///
///
diff --git a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj
index 95dedd372f61c81948a3c0bf23d035edf6b5926b..5e0efe2033ba54e330726f614c6994ca4cb09354 100644
--- a/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj
+++ b/src/blazor/admin/BootstrapAdmin.Web/BootstrapAdmin.Web.csproj
@@ -7,9 +7,9 @@
-
+
-
+
diff --git a/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs
index 76dbd1740d8de30dc241bbc8ee3fd494319f0128..4f7760156fdda232c0880ff3864c99da90b2932c 100644
--- a/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs
+++ b/src/blazor/admin/BootstrapAdmin.Web/Extensions/ServicesExtensions.cs
@@ -2,6 +2,7 @@
using BootstrapAdmin.Web.Services.SMS;
using BootstrapAdmin.Web.Services.SMS.Tencent;
using Longbow.Tasks;
+using Microsoft.EntityFrameworkCore;
using System.Text;
namespace Microsoft.Extensions.DependencyInjection
@@ -74,15 +75,15 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddScoped();
// 增加 EFCore 数据服务
- //services.AddEFCoreDataAccessServices((provider, option) =>
- //{
- // var configuration = provider.GetRequiredService();
- // var connString = configuration.GetConnectionString("bb");
- // option.UseSqlite(connString);
- //});
+ services.AddEFCoreDataAccessServices((provider, option) =>
+ {
+ var configuration = provider.GetRequiredService();
+ var connString = configuration.GetConnectionString("bb");
+ option.UseSqlite(connString);
+ });
// 增加 PetaPoco 数据服务
- services.AddPetaPocoDataAccessServices();
+ //services.AddPetaPocoDataAccessServices();
// 增加后台任务
services.AddTaskServices();
diff --git a/src/blazor/admin/BootstrapAdmin.Web/Jobs/DBLogTask.cs b/src/blazor/admin/BootstrapAdmin.Web/Jobs/DBLogTask.cs
index 806cd8a6e614f7072cb49fcb02e38fa11aeeea8c..f6bcde9c0cb3d561cf42fe949b148da0c6e5b5e0 100644
--- a/src/blazor/admin/BootstrapAdmin.Web/Jobs/DBLogTask.cs
+++ b/src/blazor/admin/BootstrapAdmin.Web/Jobs/DBLogTask.cs
@@ -1,6 +1,5 @@
using BootstrapAdmin.DataAccess.Models;
using Longbow.Tasks;
-using PetaPoco;
using System.Collections.Concurrent;
namespace BootstrapAdmin.Web.Jobs