!95 feat(#I4OWBZ): add EFCore support

* refactor: 修改方法签名
* refactor: GetAll 改为公开接口
* refactor: 移除枚举转换
* fix: 消除警告
* Merge remote-tracking branch 'origin/master' into dev-blazor-ef
* feat: 配置实体
* fix: 修复菜单获取不正确
* feat: 开启EF数据服务
* feat: 修复菜单导航
* chore: 格式化文档
* chore: 更新网站端口
* feat: 增加数据库日志任务
* feat: 增加任务管理
* feat: 增加保存健康检查方法
* feat: 完善EF数据服务
* feat: 开启EF数据服务
* chore: 升级EF包
* feat: 配置EF表关系
* feat: 添加 EFCore 服务
This commit is contained in:
Nine 2021-12-31 06:41:51 +00:00 committed by Argo
parent 541a2714b7
commit bc6ec6be12
26 changed files with 1165 additions and 466 deletions

View File

@ -2,7 +2,8 @@
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="6.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.1" />
</ItemGroup>
<ItemGroup>

View File

@ -1,49 +1,84 @@
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
namespace BootstrapAdmin.DataAccess.EFCore;
/// <summary>
///
/// </summary>
public class BootstrapAdminContext : DbContext
namespace BootstrapAdmin.DataAccess.EFCore
{
/// <summary>
/// 构造函数
///
/// </summary>
/// <param name="options"></param>
public BootstrapAdminContext(DbContextOptions<BootstrapAdminContext> options) : base(options)
public class BootstrapAdminContext : DbContext
{
/// <summary>
/// 构造函数
/// </summary>
/// <param name="options"></param>
public BootstrapAdminContext(DbContextOptions<BootstrapAdminContext> options) : base(options)
{
}
}
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Dict>? Dicts { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Dict>? Dicts { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<User>? Users { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<User>? Users { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Navigation>? Navigations { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Role>? Roles { get; set; }
/// <summary>
///
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().Ignore(u => u.Period);
modelBuilder.Entity<User>().Ignore(u => u.NewPassword);
modelBuilder.Entity<User>().Ignore(u => u.CofirmPassword);
modelBuilder.Entity<User>().Ignore(u => u.IsReset);
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<UserRole>? UserRole { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Navigation>? Navigations { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<NavigationRole>? NavigationRole { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<Group>? Groups { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<UserGroup>? UserGroup { get; set; }
/// <summary>
///
/// </summary>
[NotNull]
public DbSet<RoleGroup>? RoleGroup { get; set; }
/// <summary>
///
/// </summary>
/// <param name="modelBuilder"></param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
EntityConfiguration.Configure(modelBuilder);
}
}
}

View File

@ -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
{
/// <summary>
///
/// </summary>
/// <param name="builder"></param>
public static void Configure(this ModelBuilder builder)
{
var converter = new ValueConverter<string?, int>(
v => Convert.ToInt32(v),
v => v.ToString(),
new ConverterMappingHints(valueGeneratorFactory: (p, t) => new GuidStringGenerator()));
builder.Entity<User>().ToTable("Users");
builder.Entity<User>().Ignore(u => u.Period);
builder.Entity<User>().Ignore(u => u.NewPassword);
builder.Entity<User>().Ignore(u => u.ConfirmPassword);
builder.Entity<User>().Ignore(u => u.IsReset);
builder.Entity<User>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
builder.Entity<User>().HasMany(s => s.Roles).WithMany(s => s.Users).UsingEntity<UserRole>(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<User>().HasMany(s => s.Groups).WithMany(s => s.Users).UsingEntity<UserGroup>(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<UserRole>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
builder.Entity<Role>().ToTable("Roles");
builder.Entity<Role>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
builder.Entity<Role>().HasMany(s => s.Navigations).WithMany(s => s.Roles).UsingEntity<NavigationRole>(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<Role>().HasMany(s => s.Groups).WithMany(s => s.Roles).UsingEntity<RoleGroup>(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<Navigation>().ToTable("Navigations");
builder.Entity<Navigation>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
builder.Entity<Navigation>().Ignore(s => s.HasChildren);
builder.Entity<Dict>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
builder.Entity<Group>().Property(s => s.Id).HasConversion(converter).ValueGeneratedOnAdd();
}
}
internal class GuidStringGenerator : ValueGenerator
{
public override bool GeneratesTemporaryValues => false;
protected override object? NextValue(EntityEntry entry) => "0";
}

View File

@ -45,8 +45,12 @@ public static class ServicesExtensions
// 增加数据服务
services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>));
services.AddSingleton<INavigation, NavigationsService>();
services.AddSingleton<IDict, DictService>();
return services;
services.AddSingleton<INavigation, NavigationsService>();
services.AddSingleton<IDict, DictService>();
services.AddSingleton<IUser, UserService>();
services.AddSingleton<IRole, RoleService>();
services.AddSingleton<IGroup, GroupService>();
services.AddSingleton<ILogin, LoginService>();
return services;
}
}
}

View File

@ -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<Dict> GetAll()
{
throw new NotImplementedException();
}
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; set; }
public Dictionary<string, string> GetApps()
{
throw new NotImplementedException();
}
private string AppId { get; set; }
public Dictionary<string, string> GetLogins()
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
/// <param name="configuration"></param>
public DictService(IDbContextFactory<BootstrapAdminContext> factory, IConfiguration configuration)
{
DbFactory = factory;
AppId = configuration.GetValue("AppId", "BA");
}
public Dictionary<string, string> GetThemes()
{
throw new NotImplementedException();
}
private List<Dict> GetAll()
{
using var context = DbFactory.CreateDbContext();
return context.Dicts.ToList();
}
public string GetWebFooter()
{
throw new NotImplementedException();
}
public Dictionary<string, string> GetApps()
{
var dicts = GetAll();
return dicts.Where(d => d.Category == "应用程序").Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
}
public string GetWebTitle()
{
throw new NotImplementedException();
}
public Dictionary<string, string> GetLogins()
{
var dicts = GetAll();
return dicts.Where(d => d.Category == "系统首页").Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).ToDictionary(i => i.Key, i => i.Value);
}
public bool IsDemo()
{
throw new NotImplementedException();
}
public Dictionary<string, string> GetThemes()
{
var dicts = GetAll();
return dicts.Where(d => d.Category == "网站样式").Select(d => new KeyValuePair<string, string>(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 SaveHealthCheck(bool enable = true)
{
throw new NotImplementedException();
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)
{
return true;
}
}
}

View File

@ -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<BootstrapAdminContext> DbFactory;
public GroupService(IDbContextFactory<BootstrapAdminContext> dbFactory) => DbFactory = dbFactory;
public List<Group> GetAll()
{
using var dbcontext = DbFactory.CreateDbContext();
return dbcontext.Groups.ToList();
}
public List<string> GetGroupsByRoleId(string? roleId)
{
using var dbcontext = DbFactory.CreateDbContext();
return dbcontext.RoleGroup.Where(s => s.RoleId == roleId).Select(s => s.GroupId!).ToList();
}
public List<string> 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<string> 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<string> 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;
}
}
}

View File

@ -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<bool> Log(string userName, bool result)
{
return Task.FromResult(true);
}
}

View File

@ -2,40 +2,57 @@
using BootstrapAdmin.DataAccess.Models;
using Microsoft.EntityFrameworkCore;
namespace BootstrapAdmin.DataAccess.EFCore.Services;
/// <summary>
///
/// </summary>
class NavigationsService : INavigation
namespace BootstrapAdmin.DataAccess.EFCore.Services
{
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; set; }
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
public NavigationsService(IDbContextFactory<BootstrapAdminContext> factory) => DbFactory = factory;
/// <summary>
/// 获得指定用户名可访问的所有菜单集合
/// </summary>
/// <param name="userName">当前用户名</param>
/// <returns>未层次化的菜单集合</returns>
public List<Navigation> GetAllMenus(string userName)
class NavigationsService : INavigation
{
using var context = DbFactory.CreateDbContext();
//return context..Fetch<Models.Navigations>($"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<Navigation>();
}
private IDbContextFactory<BootstrapAdminContext> DbFactory { get; set; }
public List<string> GetMenusByRoleId(string? roleId)
{
throw new NotImplementedException();
}
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
public NavigationsService(IDbContextFactory<BootstrapAdminContext> factory) => DbFactory = factory;
public bool SaveMenusByRoleId(string? roleId, List<string> menuIds)
{
throw new NotImplementedException();
/// <summary>
/// 获得指定用户名可访问的所有菜单集合
/// </summary>
/// <param name="userName">当前用户名</param>
/// <returns>未层次化的菜单集合</returns>
public List<Navigation> GetAllMenus(string userName)
{
using var context = DbFactory.CreateDbContext();
var user = context.Set<User>().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<Navigation>();
return user.Roles!.SelectMany(s => s.Navigations!).ToList();
}
public List<string> 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<string> 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;
}
}
}
}

View File

@ -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<BootstrapAdminContext> DbFactory;
public RoleService(IDbContextFactory<BootstrapAdminContext> dbFactory) => DbFactory = dbFactory;
public List<Role> GetAll()
{
using var dbcontext = DbFactory.CreateDbContext();
return dbcontext.Roles.ToList();
}
public List<string> GetRolesByGroupId(string? groupId)
{
using var dbcontext = DbFactory.CreateDbContext();
return dbcontext.RoleGroup.Where(s => s.GroupId == groupId).Select(s => s.RoleId!).ToList();
}
public List<string> GetRolesByMenuId(string? menuId)
{
using var dbcontext = DbFactory.CreateDbContext();
return dbcontext.NavigationRole.Where(s => s.NavigationId == menuId).Select(s => s.RoleId!).ToList();
}
public List<string> 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<string> 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<string> 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<string> 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;
}
}
}

View File

@ -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<BootstrapAdminContext> DbFactory { get; set; }
public UserService(IDbContextFactory<BootstrapAdminContext> factory) => DbFactory = factory;
public List<User> 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<string> GetApps(string userName)
{
return new List<string> { "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<string> 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<string>();
}
public List<string> GetUsersByGroupId(string? groupId)
{
using var context = DbFactory.CreateDbContext();
return context.UserGroup.Where(s => s.GroupId == groupId).Select(s => s.UserId!).ToList();
}
public List<string> 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<string> 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<string> 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<string> 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;
}
}

View File

@ -1,32 +1,33 @@
using System.ComponentModel;
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
/// 后台数据库脚本执行日志实体类
/// </summary>
public class DBLog
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 获得/设置 主键ID
/// 后台数据库脚本执行日志实体类
/// </summary>
public string? Id { get; set; }
public class DBLog
{
/// <summary>
/// 获得/设置 主键ID
/// </summary>
public string? Id { get; set; }
/// <summary>
/// 获得/设置 当前登陆名
/// </summary>
[DisplayName("所属用户")]
public string? UserName { get; set; }
/// <summary>
/// 获得/设置 当前登陆名
/// </summary>
[DisplayName("所属用户")]
public string? UserName { get; set; }
/// <summary>
/// 获得/设置 数据库执行脚本
/// </summary>
[DisplayName("脚本内容")]
public string SQL { get; set; } = "";
/// <summary>
/// 获得/设置 数据库执行脚本
/// </summary>
[DisplayName("脚本内容")]
public string SQL { get; set; } = "";
/// <summary>
/// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
/// </summary>
[DisplayName("执行时间")]
public DateTime LogTime { get; set; }
/// <summary>
/// 获取/设置 用户角色关联状态 checked 标示已经关联 '' 标示未关联
/// </summary>
[DisplayName("执行时间")]
public DateTime LogTime { get; set; }
}
}

View File

@ -1,36 +1,57 @@
using System.ComponentModel.DataAnnotations;
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
/// Group 实体类
/// </summary>
public class Group
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 获得/设置 主键 ID
/// Group 实体类
/// </summary>
public string? Id { get; set; }
public class Group
{
/// <summary>
/// 获得/设置 主键 ID
/// </summary>
public string? Id { get; set; }
/// <summary>
/// 获得/设置 群组名称
/// </summary>
[Display(Name = "群组名称")]
[NotNull]
public string? GroupName { get; set; }
/// <summary>
/// 获得/设置 群组名称
/// </summary>
[Display(Name = "群组名称")]
[NotNull]
public string? GroupName { get; set; }
/// <summary>
/// 获得/设置 群组编码
/// </summary>
[Display(Name = "群组编码")]
[NotNull]
public string? GroupCode { get; set; }
/// <summary>
/// 获得/设置 群组编码
/// </summary>
[Display(Name = "群组编码")]
[NotNull]
public string? GroupCode { get; set; }
/// <summary>
/// 获得/设置 群组描述
/// </summary>
[Display(Name = "群组描述")]
public string? Description { get; set; }
/// <summary>
/// 获得/设置 群组描述
/// </summary>
[Display(Name = "群组描述")]
public string? Description { get; set; }
public override string ToString() => $"{GroupName} ({GroupCode})";
/// <summary>
///
/// </summary>
public ICollection<User>? Users { get; set; }
/// <summary>
///
/// </summary>
public ICollection<UserGroup>? UserGroup { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Role>? Roles { get; set; }
/// <summary>
///
/// </summary>
public List<RoleGroup>? RoleGroup { get; set; }
public override string ToString() => $"{GroupName} ({GroupCode})";
}
}

View File

@ -2,75 +2,86 @@
using System.ComponentModel.DataAnnotations;
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
/// Bootstrap Admin 后台管理菜单相关操作实体类
/// </summary>
public class Navigation
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 获得/设置 菜单主键ID
/// Bootstrap Admin 后台管理菜单相关操作实体类
/// </summary>
public string? Id { set; get; }
public class Navigation
{
/// <summary>
/// 获得/设置 菜单主键ID
/// </summary>
public string? Id { set; get; }
/// <summary>
/// 获得/设置 父级菜单ID 默认为 0
/// </summary>
public string ParentId { set; get; } = "0";
/// <summary>
/// 获得/设置 父级菜单ID 默认为 0
/// </summary>
public string ParentId { set; get; } = "0";
/// <summary>
/// 获得/设置 菜单名称
/// </summary>
[Display(Name = "名称")]
[NotNull]
public string? Name { get; set; }
/// <summary>
/// 获得/设置 菜单名称
/// </summary>
[Display(Name = "名称")]
[NotNull]
public string? Name { get; set; }
/// <summary>
/// 获得/设置 菜单序号
/// </summary>
[Display(Name = "序号")]
public int Order { get; set; }
/// <summary>
/// 获得/设置 菜单序号
/// </summary>
[Display(Name = "序号")]
public int Order { get; set; }
/// <summary>
/// 获得/设置 菜单图标
/// </summary>
[Display(Name = "图标")]
public string? Icon { get; set; }
/// <summary>
/// 获得/设置 菜单图标
/// </summary>
[Display(Name = "图标")]
public string? Icon { get; set; }
/// <summary>
/// 获得/设置 菜单URL地址
/// </summary>
[NotNull]
[Display(Name = "地址")]
public string? Url { get; set; }
/// <summary>
/// 获得/设置 菜单URL地址
/// </summary>
[NotNull]
[Display(Name = "地址")]
public string? Url { get; set; }
/// <summary>
/// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
/// </summary>
[Display(Name = "类别")]
public EnumNavigationCategory Category { get; set; }
/// <summary>
/// 获得/设置 菜单分类, 0 表示系统菜单 1 表示用户自定义菜单
/// </summary>
[Display(Name = "类别")]
public EnumNavigationCategory Category { get; set; }
/// <summary>
/// 获得/设置 链接目标
/// </summary>
[Display(Name = "目标")]
public string? Target { get; set; }
/// <summary>
/// 获得/设置 链接目标
/// </summary>
[Display(Name = "目标")]
public string? Target { get; set; }
/// <summary>
/// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
/// </summary>
[Display(Name = "类型")]
public EnumResource IsResource { get; set; }
/// <summary>
/// 获得/设置 是否为资源文件, 0 表示菜单 1 表示资源 2 表示按钮
/// </summary>
[Display(Name = "类型")]
public EnumResource IsResource { get; set; }
/// <summary>
/// 获得/设置 所属应用程序此属性由BA后台字典表分配
/// </summary>
[Display(Name = "所属应用")]
public string? Application { get; set; }
/// <summary>
/// 获得/设置 所属应用程序此属性由BA后台字典表分配
/// </summary>
[Display(Name = "所属应用")]
public string? Application { get; set; }
/// <summary>
///
/// </summary>
public bool HasChildren { get; set; }
/// <summary>
///
/// </summary>
public bool HasChildren { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Role>? Roles { get; set; }
/// <summary>
///
/// </summary>
public List<NavigationRole>? NavigationRoles { get; set; }
}
}

View File

@ -0,0 +1,29 @@
namespace BootstrapAdmin.DataAccess.Models;
public class NavigationRole
{
/// <summary>
///
/// </summary>
public string? Id { get; set; }
/// <summary>
///
/// </summary>
public string? NavigationId { get; set; }
/// <summary>
///
/// </summary>
public Navigation? Navigation { get; set; }
/// <summary>
///
/// </summary>
public string? RoleId { get; set; }
/// <summary>
///
/// </summary>
public Role? Role { get; set; }
}

View File

@ -1,29 +1,61 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
/// Role 实体类
/// </summary>
public class Role
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 获得/设置 角色主键ID
/// Role 实体类
/// </summary>
public string? Id { get; set; }
public class Role
{
/// <summary>
/// 获得/设置 角色主键ID
/// </summary>
public string? Id { get; set; }
/// <summary>
/// 获得/设置 角色名称
/// </summary>
[DisplayName("角色名称")]
[NotNull]
public string? RoleName { get; set; }
/// <summary>
/// 获得/设置 角色名称
/// </summary>
[DisplayName("角色名称")]
[NotNull]
public string? RoleName { get; set; }
/// <summary>
/// 获得/设置 角色描述
/// </summary>
[DisplayName("角色描述")]
[NotNull]
public string? Description { get; set; }
/// <summary>
/// 获得/设置 角色描述
/// </summary>
[DisplayName("角色描述")]
[NotNull]
public string? Description { get; set; }
/// <summary>
///
/// </summary>
public ICollection<User>? Users { get; set; }
/// <summary>
///
/// </summary>
public List<UserRole>? UserRoles { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Navigation>? Navigations { get; set; }
/// <summary>
///
/// </summary>
public List<NavigationRole>? NavigationRoles { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Group>? Groups { get; set; }
/// <summary>
///
/// </summary>
public List<RoleGroup>? RoleGroup { get; set; }
}
}

View File

@ -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; }
}

View File

@ -1,151 +1,172 @@
using System.ComponentModel.DataAnnotations;
namespace BootstrapAdmin.DataAccess.Models;
/// <summary>
///
/// </summary>
public class User
namespace BootstrapAdmin.DataAccess.Models
{
/// <summary>
/// 获得/设置 系统登录用户名
///
/// </summary>
[Display(Name = "登录名称")]
public string? UserName { get; set; }
public class User
{
/// <summary>
/// 获得/设置 系统登录用户名
/// </summary>
[Display(Name = "登录名称")]
public string? UserName { get; set; }
/// <summary>
/// 获得/设置 用户显示名称
/// </summary>
[Display(Name = "显示名称")]
[Required(ErrorMessage = "{0}不可为空")]
[MaxLength(50, ErrorMessage = "{0}不能超过 50 个字符")]
public string? DisplayName { get; set; }
/// <summary>
/// 获得/设置 用户头像图标路径
/// </summary>
[Display(Name = "用户头像")]
public string? Icon { get; set; }
/// <summary>
/// 获得/设置 用户设置样式表名称
/// </summary>
[Display(Name = "主题")]
public string? Css { get; set; }
/// <summary>
/// 获得/设置 用户默认登陆 App 标识
/// </summary>
[Display(Name = "默认 APP")]
public string? App { get; set; }
/// <summary>
/// 获得/设置 用户主键ID
/// </summary>
public string? Id { get; set; }
/// <summary>
/// 获取/设置 密码
/// </summary>
[Display(Name = "密码")]
[Required(ErrorMessage = "{0}不可为空")]
public string? Password { get; set; }
/// <summary>
/// 获取/设置 密码盐
/// </summary>
public string? PassSalt { get; set; }
/// <summary>
/// 获得/设置 用户注册时间
/// </summary>
[Display(Name = "注册时间")]
public DateTime RegisterTime { get; set; } = DateTime.Now;
/// <summary>
/// 获得/设置 用户被批复时间
/// </summary>
[Display(Name = "授权时间")]
public DateTime? ApprovedTime { get; set; }
/// <summary>
/// 获得/设置 用户批复人
/// </summary>
[Display(Name = "授权人")]
public string? ApprovedBy { get; set; }
/// <summary>
/// 获得/设置 用户的申请理由
/// </summary>
[Display(Name = "说明")]
public string? Description { get; set; }
/// <summary>
/// 获得/设置 通知描述 2分钟内为刚刚
/// </summary>
public string? Period { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
[Display(Name = "新密码")]
[Required(ErrorMessage = "{0}不可为空")]
[NotNull]
public string? NewPassword { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
[Display(Name = "确认密码")]
[Required(ErrorMessage = "{0}不可为空")]
[Compare("NewPassword", ErrorMessage = "{0}与{1}不一致")]
[NotNull]
public string? ConfirmPassword { get; set; }
/// <summary>
/// 获得/设置 是否重置密码
/// </summary>
public int IsReset { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Role>? Roles { get; set; }
/// <summary>
///
/// </summary>
public List<UserRole>? UserRoles { get; set; }
/// <summary>
///
/// </summary>
public ICollection<Group>? Groups { get; set; }
/// <summary>
///
/// </summary>
public ICollection<UserGroup>? UserGroup { get; set; }
/// <summary>
/// 获得/设置 默认格式为 DisplayName (UserName)
/// </summary>
/// <returns></returns>
public override string ToString() => $"{DisplayName} ({UserName})";
}
/// <summary>
/// 获得/设置 用户显示名称
/// 用户状态枚举类型
/// </summary>
[Display(Name = "显示名称")]
[Required(ErrorMessage = "{0}不可为空")]
[MaxLength(50, ErrorMessage = "{0}不能超过 50 个字符")]
public string? DisplayName { get; set; }
public enum UserStates
{
/// <summary>
/// 更改密码
/// </summary>
ChangePassword,
/// <summary>
/// 获得/设置 用户头像图标路径
/// </summary>
[Display(Name = "用户头像")]
public string? Icon { get; set; }
/// <summary>
/// 更改样式
/// </summary>
ChangeTheme,
/// <summary>
/// 获得/设置 用户设置样式表名称
/// </summary>
[Display(Name = "主题")]
public string? Css { get; set; }
/// <summary>
/// 更改显示名称
/// </summary>
ChangeDisplayName,
/// <summary>
/// 获得/设置 用户默认登陆 App 标识
/// </summary>
[Display(Name = "默认 APP")]
public string? App { get; set; }
/// <summary>
/// 审批用户
/// </summary>
ApproveUser,
/// <summary>
/// 获得/设置 用户主键ID
/// </summary>
public string? Id { get; set; }
/// <summary>
/// 拒绝用户
/// </summary>
RejectUser,
/// <summary>
/// 获取/设置 密码
/// </summary>
[Display(Name = "密码")]
[Required(ErrorMessage = "{0}不可为空")]
public string? Password { get; set; }
/// <summary>
/// 获取/设置 密码盐
/// </summary>
public string? PassSalt { get; set; }
/// <summary>
/// 获得/设置 用户注册时间
/// </summary>
[Display(Name = "注册时间")]
public DateTime RegisterTime { get; set; } = DateTime.Now;
/// <summary>
/// 获得/设置 用户被批复时间
/// </summary>
[Display(Name = "授权时间")]
public DateTime? ApprovedTime { get; set; }
/// <summary>
/// 获得/设置 用户批复人
/// </summary>
[Display(Name = "授权人")]
public string? ApprovedBy { get; set; }
/// <summary>
/// 获得/设置 用户的申请理由
/// </summary>
[Display(Name = "说明")]
public string? Description { get; set; }
/// <summary>
/// 获得/设置 通知描述 2分钟内为刚刚
/// </summary>
public string? Period { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
[Display(Name = "新密码")]
[Required(ErrorMessage = "{0}不可为空")]
[NotNull]
public string? NewPassword { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
[Display(Name = "确认密码")]
[Required(ErrorMessage = "{0}不可为空")]
[Compare("NewPassword", ErrorMessage = "{0}与{1}不一致")]
[NotNull]
public string? ConfirmPassword { get; set; }
/// <summary>
/// 获得/设置 是否重置密码
/// </summary>
public int IsReset { get; set; }
/// <summary>
/// 获得/设置 默认格式为 DisplayName (UserName)
/// </summary>
/// <returns></returns>
public override string ToString() => $"{DisplayName} ({UserName})";
}
/// <summary>
/// 用户状态枚举类型
/// </summary>
public enum UserStates
{
/// <summary>
/// 更改密码
/// </summary>
ChangePassword,
/// <summary>
/// 更改样式
/// </summary>
ChangeTheme,
/// <summary>
/// 更改显示名称
/// </summary>
ChangeDisplayName,
/// <summary>
/// 审批用户
/// </summary>
ApproveUser,
/// <summary>
/// 拒绝用户
/// </summary>
RejectUser,
/// <summary>
/// 保存默认应用
/// </summary>
SaveApp
/// <summary>
/// 保存默认应用
/// </summary>
SaveApp
}
}

View File

@ -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
{
/// <summary>
///
/// </summary>
public string? Id { get; set; }
/// <summary>
///
/// </summary>
public string? UserId { get; set; }
/// <summary>
///
/// </summary>
public User? User { get; set; }
/// <summary>
///
/// </summary>
public string? GroupId { get; set; }
/// <summary>
///
/// </summary>
public Group? Group { get; set; }
}

View File

@ -0,0 +1,29 @@
namespace BootstrapAdmin.DataAccess.Models;
public class UserRole
{
/// <summary>
///
/// </summary>
public string? Id { get; set; }
/// <summary>
///
/// </summary>
public string? UserId { get; set; }
/// <summary>
///
/// </summary>
public User? User { get; set; }
/// <summary>
///
/// </summary>
public string? RoleId { get; set; }
/// <summary>
///
/// </summary>
public Role? Role { get; set; }
}

View File

@ -11,6 +11,11 @@ class DictService : BaseDatabase, IDict
{
private string AppId { get; set; }
/// <summary>
///
/// </summary>
/// <param name="db"></param>
/// <param name="configuration"></param>
public DictService(IDatabase db, IConfiguration configuration)
{
Database = db;
@ -108,7 +113,7 @@ class DictService : BaseDatabase, IDict
/// </summary>
/// <param name="isDemo"></param>
/// <returns></returns>
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;
/// <summary>
///
@ -116,5 +121,5 @@ class DictService : BaseDatabase, IDict
/// <param name="enable"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
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;
}

View File

@ -1,71 +1,73 @@
using BootstrapAdmin.DataAccess.Models;
namespace BootstrapAdmin.Web.Core;
/// <summary>
/// Dict 字典表接口
/// </summary>
public interface IDict
namespace BootstrapAdmin.Web.Core
{
/// <summary>
/// 获得 所有数据方法
/// Dict 字典表接口
/// </summary>
/// <returns></returns>
List<Dict> GetAll();
public interface IDict
{
/// <summary>
/// 获得 配置所有的 App 集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetApps();
/// <summary>
///
/// </summary>
/// <returns></returns>
List<Dict> GetAll();
/// <summary>
/// 获得 配置所有的登录页集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetLogins();
/// <summary>
/// 获得 配置所有的 App 集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetApps();
/// <summary>
/// 获得 配置所有的主题集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetThemes();
/// <summary>
/// 获得 配置所有的登录页集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetLogins();
/// <summary>
/// 获取当前系统配置是否为演示模式
/// </summary>
/// <returns></returns>
bool IsDemo();
/// <summary>
/// 获得 配置所有的主题集合
/// </summary>
/// <returns></returns>
Dictionary<string, string> GetThemes();
/// <summary>
/// 保存当前网站是否为演示系统
/// </summary>
/// <param name="isDemo"></param>
/// <returns></returns>
bool SaveDemo(bool isDemo);
/// <summary>
/// 获取当前系统配置是否为演示模式
/// </summary>
/// <returns></returns>
bool IsDemo();
/// <summary>
/// 保存健康检查
/// </summary>
/// <returns></returns>
bool SaveHealthCheck(bool enable = true);
/// <summary>
/// 保存当前网站是否为演示系统
/// </summary>
/// <param name="isDemo"></param>
/// <returns></returns>
bool SaveDemo(bool isDemo);
/// <summary>
/// 获得当前授权码是否有效可更改网站设置
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
bool AuthenticateDemo(string code);
/// <summary>
/// 保存健康检查
/// </summary>
/// <returns></returns>
bool SaveHealthCheck(bool enable = true);
/// <summary>
/// 获取 站点 Title 配置信息
/// </summary>
/// <returns></returns>
string GetWebTitle();
/// <summary>
/// 获得当前授权码是否有效可更改网站设置
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
bool AuthenticateDemo(string code);
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <returns></returns>
string GetWebFooter();
/// <summary>
/// 获取 站点 Title 配置信息
/// </summary>
/// <returns></returns>
string GetWebTitle();
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <returns></returns>
string GetWebFooter();
}
}

View File

@ -1,29 +1,30 @@
using BootstrapAdmin.DataAccess.Models;
namespace BootstrapAdmin.Web.Core;
/// <summary>
///
/// </summary>
public interface INavigation
namespace BootstrapAdmin.Web.Core
{
/// <summary>
///
/// </summary>
/// <returns></returns>
List<Navigation> GetAllMenus(string userName);
public interface INavigation
{
/// <summary>
///
/// </summary>
/// <returns></returns>
List<Navigation> GetAllMenus(string userName);
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
List<string> GetMenusByRoleId(string? roleId);
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
List<string> GetMenusByRoleId(string? roleId);
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
bool SaveMenusByRoleId(string? roleId, List<string> menuIds);
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
bool SaveMenusByRoleId(string? roleId, List<string> menuIds);
}
}

View File

@ -16,9 +16,9 @@ public interface IRole
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <param name="groupId"></param>
/// <returns></returns>
List<string> GetRolesByGroupId(string? userId);
List<string> GetRolesByGroupId(string? groupId);
/// <summary>
///
@ -31,17 +31,17 @@ public interface IRole
/// <summary>
///
/// </summary>
/// <param name="groupId"></param>
/// <param name="userId"></param>
/// <returns></returns>
List<string> GetRolesByUserId(string? groupId);
List<string> GetRolesByUserId(string? userId);
/// <summary>
///
/// </summary>
/// <param name="groupId"></param>
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
bool SaveRolesByUserId(string? groupId, IEnumerable<string> roleIds);
bool SaveRolesByUserId(string? userId, IEnumerable<string> roleIds);
/// <summary>
///

View File

@ -7,9 +7,9 @@
<ItemGroup>
<PackageReference Include="Longbow.Tasks" Version="5.2.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BootstrapAdmin.DataAccess.PetaPoco\BootstrapAdmin.DataAccess.PetaPoco.csproj" />
<ProjectReference Include="..\BootstrapAdmin.DataAccess.EFCore\BootstrapAdmin.DataAccess.EFCore.csproj" />
</ItemGroup>
<ItemGroup>

View File

@ -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<BootstrapAppContext>();
// 增加 EFCore 数据服务
//services.AddEFCoreDataAccessServices((provider, option) =>
//{
// var configuration = provider.GetRequiredService<IConfiguration>();
// var connString = configuration.GetConnectionString("bb");
// option.UseSqlite(connString);
//});
services.AddEFCoreDataAccessServices((provider, option) =>
{
var configuration = provider.GetRequiredService<IConfiguration>();
var connString = configuration.GetConnectionString("bb");
option.UseSqlite(connString);
});
// 增加 PetaPoco 数据服务
services.AddPetaPocoDataAccessServices();
//services.AddPetaPocoDataAccessServices();
// 增加后台任务
services.AddTaskServices();

View File

@ -1,6 +1,5 @@
using BootstrapAdmin.DataAccess.Models;
using Longbow.Tasks;
using PetaPoco;
using System.Collections.Concurrent;
namespace BootstrapAdmin.Web.Jobs