diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs index 3d27df21..7ba57af4 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/BootstrapAdminContext.cs @@ -1,50 +1,49 @@ using BootstrapAdmin.DataAccess.Models; using Microsoft.EntityFrameworkCore; -namespace BootstrapAdmin.DataAccess.EFCore +namespace BootstrapAdmin.DataAccess.EFCore; + +/// +/// +/// +public class BootstrapAdminContext : DbContext { + /// + /// 构造函数 + /// + /// + public BootstrapAdminContext(DbContextOptions options) : base(options) + { + + } + /// /// /// - public class BootstrapAdminContext : DbContext + [NotNull] + public DbSet? Dicts { get; set; } + + /// + /// + /// + [NotNull] + public DbSet? Users { get; set; } + + /// + /// + /// + [NotNull] + public DbSet? Navigations { get; set; } + + /// + /// + /// + /// + protected override void OnModelCreating(ModelBuilder modelBuilder) { - /// - /// 构造函数 - /// - /// - public BootstrapAdminContext(DbContextOptions options) : base(options) - { - - } - - /// - /// - /// - [NotNull] - public DbSet? Dicts { get; set; } - - /// - /// - /// - [NotNull] - public DbSet? Users { get; set; } - - /// - /// - /// - [NotNull] - public DbSet? Navigations { 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); - } + modelBuilder.Entity().Ignore(u => u.Period); + modelBuilder.Entity().Ignore(u => u.NewPassword); + modelBuilder.Entity().Ignore(u => u.CofirmPassword); + modelBuilder.Entity().Ignore(u => u.IsReset); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs index 979d84ae..78439a7c 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Extensions/ServicesExtensions.cs @@ -4,50 +4,49 @@ using BootstrapAdmin.Web.Core; using BootstrapBlazor.Components; using Microsoft.EntityFrameworkCore; -namespace Microsoft.Extensions.DependencyInjection +namespace Microsoft.Extensions.DependencyInjection; + +/// +/// +/// +public static class ServicesExtensions { /// /// /// - public static class ServicesExtensions + /// + /// + /// + /// + public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services, Action optionConfigure, ServiceLifetime lifetime = ServiceLifetime.Singleton) { - /// - /// - /// - /// - /// - /// - /// - public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services, Action optionConfigure, ServiceLifetime lifetime = ServiceLifetime.Singleton) - { - services.AddDbContextFactory(optionConfigure, lifetime); + services.AddDbContextFactory(optionConfigure, lifetime); - services.AddServices(); - return services; - } - /// - /// - /// - /// - /// - /// - /// - public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services, Action optionConfigure, ServiceLifetime lifetime = ServiceLifetime.Singleton) - { - services.AddDbContextFactory(optionConfigure, lifetime); + services.AddServices(); + return services; + } + /// + /// + /// + /// + /// + /// + /// + public static IServiceCollection AddEFCoreDataAccessServices(this IServiceCollection services, Action optionConfigure, ServiceLifetime lifetime = ServiceLifetime.Singleton) + { + services.AddDbContextFactory(optionConfigure, lifetime); - services.AddServices(); - return services; - } + services.AddServices(); + return services; + } - private static IServiceCollection AddServices(this IServiceCollection services) - { - // 增加数据服务 - services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>)); + private static IServiceCollection AddServices(this IServiceCollection services) + { + // 增加数据服务 + services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>)); - services.AddSingleton(); - services.AddSingleton(); - return services; - } + services.AddSingleton(); + services.AddSingleton(); + return services; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DefaultDataService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DefaultDataService.cs index abf6c91b..b9ec6674 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DefaultDataService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DefaultDataService.cs @@ -5,91 +5,90 @@ using BootstrapBlazor.Components; using Microsoft.EntityFrameworkCore; -namespace BootstrapAdmin.DataAccess.EFCore.Services +namespace BootstrapAdmin.DataAccess.EFCore.Services; + +/// +/// EFCore ORM 的 IDataService 接口实现 +/// +class DefaultDataService : DataServiceBase where TModel : class, new() { + private IDbContextFactory DbFactory { get; } + /// - /// EFCore ORM 的 IDataService 接口实现 + /// 构造函数 /// - class DefaultDataService : DataServiceBase where TModel : class, new() + public DefaultDataService(IDbContextFactory factory) => DbFactory = factory; + + /// + /// 删除方法 + /// + /// + /// + public override async Task DeleteAsync(IEnumerable models) { - private IDbContextFactory DbFactory { get; } + // 通过模型获取主键列数据 + // 支持批量删除 + var context = DbFactory.CreateDbContext(); + context.RemoveRange(models); + return await context.SaveChangesAsync() > 0; + } - /// - /// 构造函数 - /// - public DefaultDataService(IDbContextFactory factory) => DbFactory = factory; - - /// - /// 删除方法 - /// - /// - /// - public override async Task DeleteAsync(IEnumerable models) + /// + /// 保存方法 + /// + /// + /// + /// + public override async Task SaveAsync(TModel model, ItemChangedType changedType) + { + var context = DbFactory.CreateDbContext(); + if (changedType == ItemChangedType.Add) { - // 通过模型获取主键列数据 - // 支持批量删除 - var context = DbFactory.CreateDbContext(); - context.RemoveRange(models); - return await context.SaveChangesAsync() > 0; + context.Entry(model).State = EntityState.Added; } - - /// - /// 保存方法 - /// - /// - /// - /// - public override async Task SaveAsync(TModel model, ItemChangedType changedType) + else { - var context = DbFactory.CreateDbContext(); - if (changedType == ItemChangedType.Add) - { - context.Entry(model).State = EntityState.Added; - } - else - { - context.Entry(model).State = EntityState.Modified; - } - return await context.SaveChangesAsync() > 0; + context.Entry(model).State = EntityState.Modified; } + return await context.SaveChangesAsync() > 0; + } - /// - /// 查询方法 - /// - /// - /// - public override Task> QueryAsync(QueryPageOptions option) + /// + /// 查询方法 + /// + /// + /// + public override Task> QueryAsync(QueryPageOptions option) + { + var context = DbFactory.CreateDbContext(); + var ret = new QueryData() { - var context = DbFactory.CreateDbContext(); - var ret = new QueryData() - { - IsSorted = true, - IsFiltered = true, - IsSearch = true - }; + IsSorted = true, + IsFiltered = true, + IsSearch = true + }; - var filters = option.Filters.Concat(option.Searchs).Concat(option.CustomerSearchs); - if (option.IsPage) - { - var items = context.Set() - .Where(filters.GetFilterLambda(), filters.Any()) - .Sort(option.SortName!, option.SortOrder, !string.IsNullOrEmpty(option.SortName)) - .Count(out var count) - .Page((option.PageIndex - 1) * option.PageItems, option.PageItems); + var filters = option.Filters.Concat(option.Searchs).Concat(option.CustomerSearchs); + if (option.IsPage) + { + var items = context.Set() + .Where(filters.GetFilterLambda(), filters.Any()) + .Sort(option.SortName!, option.SortOrder, !string.IsNullOrEmpty(option.SortName)) + .Count(out var count) + .Page((option.PageIndex - 1) * option.PageItems, option.PageItems); - ret.TotalCount = count; - ret.Items = items; - } - else - { - var items = context.Set() - .Where(filters.GetFilterLambda(), filters.Any()) - .Sort(option.SortName!, option.SortOrder, !string.IsNullOrEmpty(option.SortName)) - .Count(out var count); - ret.TotalCount = count; - ret.Items = items; - } - return Task.FromResult(ret); + ret.TotalCount = count; + ret.Items = items; } + else + { + var items = context.Set() + .Where(filters.GetFilterLambda(), filters.Any()) + .Sort(option.SortName!, option.SortOrder, !string.IsNullOrEmpty(option.SortName)) + .Count(out var count); + ret.TotalCount = count; + ret.Items = items; + } + return Task.FromResult(ret); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs index 11bc893b..f578b6d6 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictService.cs @@ -2,53 +2,52 @@ using BootstrapAdmin.Web.Core; using BootstrapBlazor.Components; -namespace BootstrapAdmin.DataAccess.EFCore.Services +namespace BootstrapAdmin.DataAccess.EFCore.Services; + +class DictService : IDict { - class DictService : IDict + public Dictionary GetApps() { - public Dictionary GetApps() - { - throw new NotImplementedException(); - } + throw new NotImplementedException(); + } - public Dictionary GetLogins() - { - throw new NotImplementedException(); - } + public Dictionary GetLogins() + { + throw new NotImplementedException(); + } - public Dictionary GetThemes() - { - throw new NotImplementedException(); - } + public Dictionary GetThemes() + { + throw new NotImplementedException(); + } - public string GetWebFooter() - { - throw new NotImplementedException(); - } + public string GetWebFooter() + { + throw new NotImplementedException(); + } - public string GetWebTitle() - { - throw new NotImplementedException(); - } + public string GetWebTitle() + { + throw new NotImplementedException(); + } - public bool IsDemo() - { - throw new NotImplementedException(); - } + public bool IsDemo() + { + throw new NotImplementedException(); + } - public bool SaveDemo(bool isDemo) - { - throw new NotImplementedException(); - } + public bool SaveDemo(bool isDemo) + { + throw new NotImplementedException(); + } - public bool AuthenticateDemo(string code) - { - throw new NotImplementedException(); - } + public bool AuthenticateDemo(string code) + { + throw new NotImplementedException(); + } - public bool SaveHealthCheck(bool enable = true) - { - throw new NotImplementedException(); - } + public bool SaveHealthCheck(bool enable = true) + { + throw new NotImplementedException(); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs index f34fd425..1e4b9903 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/NavigationsService.cs @@ -2,41 +2,40 @@ using BootstrapAdmin.DataAccess.Models; using Microsoft.EntityFrameworkCore; -namespace BootstrapAdmin.DataAccess.EFCore.Services +namespace BootstrapAdmin.DataAccess.EFCore.Services; + +/// +/// +/// +class NavigationsService : INavigation { + private IDbContextFactory DbFactory { get; set; } + /// /// /// - class NavigationsService : INavigation + /// + public NavigationsService(IDbContextFactory factory) => DbFactory = factory; + + /// + /// 获得指定用户名可访问的所有菜单集合 + /// + /// 当前用户名 + /// 未层次化的菜单集合 + public List GetAllMenus(string userName) { - private IDbContextFactory DbFactory { get; set; } + 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(); + } - /// - /// - /// - /// - public NavigationsService(IDbContextFactory factory) => DbFactory = factory; + public List GetMenusByRoleId(string? roleId) + { + throw new NotImplementedException(); + } - /// - /// 获得指定用户名可访问的所有菜单集合 - /// - /// 当前用户名 - /// 未层次化的菜单集合 - public List GetAllMenus(string userName) - { - 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(); - } - - public List GetMenusByRoleId(string? roleId) - { - throw new NotImplementedException(); - } - - public bool SaveMenusByRoleId(string? roleId, List menuIds) - { - throw new NotImplementedException(); - } + public bool SaveMenusByRoleId(string? roleId, List menuIds) + { + throw new NotImplementedException(); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs index c410bf13..6b3fb959 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/DBLog.cs @@ -1,33 +1,32 @@ using System.ComponentModel; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// 后台数据库脚本执行日志实体类 +/// +public class DBLog { /// - /// 后台数据库脚本执行日志实体类 + /// 获得/设置 主键ID /// - public class DBLog - { - /// - /// 获得/设置 主键ID - /// - public string? Id { get; set; } + 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/Dict.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dict.cs index 0089cc26..bee4dcf0 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dict.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Dict.cs @@ -2,43 +2,42 @@ using System.ComponentModel.DataAnnotations; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// 字典配置项 +/// +public class Dict { /// - /// 字典配置项 + /// 获得/设置 字典主键 数据库自增列 /// - public class Dict - { - /// - /// 获得/设置 字典主键 数据库自增列 - /// - public string? Id { get; set; } + public string? Id { get; set; } - /// - /// 获得/设置 字典标签 - /// - [Required(ErrorMessage = "{0}不可为空")] - [Display(Name = "字典标签")] - public string Category { get; set; } = ""; + /// + /// 获得/设置 字典标签 + /// + [Required(ErrorMessage = "{0}不可为空")] + [Display(Name = "字典标签")] + public string Category { get; set; } = ""; - /// - /// 获得/设置 字典名称 - /// - [Required(ErrorMessage = "{0}不可为空")] - [Display(Name = "字典名称")] - public string Name { get; set; } = ""; + /// + /// 获得/设置 字典名称 + /// + [Required(ErrorMessage = "{0}不可为空")] + [Display(Name = "字典名称")] + public string Name { get; set; } = ""; - /// - /// 获得/设置 字典字典值 - /// - [Required(ErrorMessage = "{0}不可为空")] - [Display(Name = "字典代码")] - public string Code { get; set; } = ""; + /// + /// 获得/设置 字典字典值 + /// + [Required(ErrorMessage = "{0}不可为空")] + [Display(Name = "字典代码")] + public string Code { get; set; } = ""; - /// - /// 获得/设置 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 - /// - [Display(Name = "字典类型")] - public EnumDictDefine Define { get; set; } = EnumDictDefine.Customer; - } + /// + /// 获得/设置 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 + /// + [Display(Name = "字典类型")] + public EnumDictDefine Define { get; set; } = EnumDictDefine.Customer; } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumDictDefine.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumDictDefine.cs index 1aceff4b..0f7a528e 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumDictDefine.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumDictDefine.cs @@ -1,22 +1,21 @@ using System.ComponentModel; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 +/// +public enum EnumDictDefine { /// - /// 字典定义值 0 表示系统使用,1 表示用户自定义 默认为 1 + /// 系统使用 /// - public enum EnumDictDefine - { - /// - /// 系统使用 - /// - [Description("系统使用")] - System, + [Description("系统使用")] + System, - /// - /// 用户自定义 - /// - [Description("自定义")] - Customer - } + /// + /// 用户自定义 + /// + [Description("自定义")] + Customer } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs index d9a48e0b..68ed3f36 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumNavigationCategory.cs @@ -1,22 +1,21 @@ using System.ComponentModel; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// 菜单分类 0 表示系统菜单 1 表示用户自定义菜单 +/// +public enum EnumNavigationCategory { /// - /// 菜单分类 0 表示系统菜单 1 表示用户自定义菜单 + /// 系统使用 /// - public enum EnumNavigationCategory - { - /// - /// 系统使用 - /// - [Description("系统使用")] - System, + [Description("系统使用")] + System, - /// - /// 用户自定义 - /// - [Description("自定义")] - Customer - } + /// + /// 用户自定义 + /// + [Description("自定义")] + Customer } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumResource.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumResource.cs index e82699fe..2874fbd2 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumResource.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/EnumResource.cs @@ -1,26 +1,25 @@ using System.ComponentModel; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// 资源类型枚举 0 表示菜单 1 表示资源 2 表示按钮 +/// +public enum EnumResource { /// - /// 资源类型枚举 0 表示菜单 1 表示资源 2 表示按钮 + /// /// - public enum EnumResource - { - /// - /// - /// - [Description("菜单")] - Navigation, - /// - /// - /// - [Description("资源")] - Resource, - /// - /// - /// - [Description("代码块")] - Block - } + [Description("菜单")] + Navigation, + /// + /// + /// + [Description("资源")] + Resource, + /// + /// + /// + [Description("代码块")] + Block } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs index b425f218..08f5b387 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Group.cs @@ -1,37 +1,36 @@ using System.ComponentModel.DataAnnotations; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// Group 实体类 +/// +public class Group { /// - /// Group 实体类 + /// 获得/设置 主键 ID /// - public class Group - { - /// - /// 获得/设置 主键 ID - /// - public string? Id { get; set; } + 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 override string ToString() => $"{GroupName} ({GroupCode})"; - } + public override string ToString() => $"{GroupName} ({GroupCode})"; } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/LoginUser.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/LoginUser.cs index 32db30c2..e612c1ff 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/LoginUser.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/LoginUser.cs @@ -1,63 +1,62 @@ using System.ComponentModel; -namespace Bootstrap.DataAccess +namespace Bootstrap.DataAccess; + +/// +/// 登录用户信息实体类 +/// +public class LoginLog { /// - /// 登录用户信息实体类 + /// 获得/设置 Id /// - public class LoginLog - { - /// - /// 获得/设置 Id - /// - public string? Id { get; set; } + public string? Id { get; set; } - /// - /// 获得/设置 用户名 - /// - [DisplayName("登录名称")] - public string UserName { get; set; } = ""; + /// + /// 获得/设置 用户名 + /// + [DisplayName("登录名称")] + public string UserName { get; set; } = ""; - /// - /// 获得/设置 登录时间 - /// - [DisplayName("登录时间")] - public DateTime LoginTime { get; set; } + /// + /// 获得/设置 登录时间 + /// + [DisplayName("登录时间")] + public DateTime LoginTime { get; set; } - /// - /// 获得/设置 登录IP地址 - /// - [DisplayName("主机")] - public string Ip { get; set; } = ""; + /// + /// 获得/设置 登录IP地址 + /// + [DisplayName("主机")] + public string Ip { get; set; } = ""; - /// - /// 获得/设置 登录浏览器 - /// - [DisplayName("浏览器")] - public string Browser { get; set; } = ""; + /// + /// 获得/设置 登录浏览器 + /// + [DisplayName("浏览器")] + public string Browser { get; set; } = ""; - /// - /// 获得/设置 登录操作系统 - /// - [DisplayName("操作系统")] - public string OS { get; set; } = ""; + /// + /// 获得/设置 登录操作系统 + /// + [DisplayName("操作系统")] + public string OS { get; set; } = ""; - /// - /// 获得/设置 登录地点 - /// - [DisplayName("登录地点")] - public string City { get; set; } = ""; + /// + /// 获得/设置 登录地点 + /// + [DisplayName("登录地点")] + public string City { get; set; } = ""; - /// - /// 获得/设置 登录是否成功 - /// - [DisplayName("登录结果")] - public string Result { get; set; } = ""; + /// + /// 获得/设置 登录是否成功 + /// + [DisplayName("登录结果")] + public string Result { get; set; } = ""; - /// - /// 获得/设置 用户 UserAgent - /// - [DisplayName("登录名称")] - public string UserAgent { get; set; } = ""; - } + /// + /// 获得/设置 用户 UserAgent + /// + [DisplayName("登录名称")] + public string UserAgent { get; set; } = ""; } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs index 4d6bc9ed..c302aaa6 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Navigation.cs @@ -2,76 +2,75 @@ using System.ComponentModel.DataAnnotations; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// Bootstrap Admin 后台管理菜单相关操作实体类 +/// +public class Navigation { /// - /// Bootstrap Admin 后台管理菜单相关操作实体类 + /// 获得/设置 菜单主键ID /// - public class Navigation - { - /// - /// 获得/设置 菜单主键ID - /// - public string? Id { set; get; } + 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; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs index 7a262c5a..ce6b65f6 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/Role.cs @@ -1,30 +1,29 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// Role 实体类 +/// +public class Role { /// - /// Role 实体类 + /// 获得/设置 角色主键ID /// - public class Role - { - /// - /// 获得/设置 角色主键ID - /// - public string? Id { get; set; } + 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; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs index 7fdfad86..54f22a9e 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.Models/User.cs @@ -1,152 +1,151 @@ using System.ComponentModel.DataAnnotations; -namespace BootstrapAdmin.DataAccess.Models +namespace BootstrapAdmin.DataAccess.Models; + +/// +/// +/// +public class User { /// - /// + /// 获得/设置 系统登录用户名 /// - 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})"; - } + [Display(Name = "登录名称")] + public string? UserName { get; set; } /// - /// 用户状态枚举类型 + /// 获得/设置 用户显示名称 /// - public enum UserStates - { - /// - /// 更改密码 - /// - ChangePassword, + [Display(Name = "显示名称")] + [Required(ErrorMessage = "{0}不可为空")] + [MaxLength(50, ErrorMessage = "{0}不能超过 50 个字符")] + public string? DisplayName { get; set; } - /// - /// 更改样式 - /// - ChangeTheme, + /// + /// 获得/设置 用户头像图标路径 + /// + [Display(Name = "用户头像")] + public string? Icon { get; set; } - /// - /// 更改显示名称 - /// - ChangeDisplayName, + /// + /// 获得/设置 用户设置样式表名称 + /// + [Display(Name = "主题")] + public string? Css { get; set; } - /// - /// 审批用户 - /// - ApproveUser, + /// + /// 获得/设置 用户默认登陆 App 标识 + /// + [Display(Name = "默认 APP")] + public string? App { get; set; } - /// - /// 拒绝用户 - /// - RejectUser, + /// + /// 获得/设置 用户主键ID + /// + public string? Id { get; set; } - /// - /// 保存默认应用 - /// - SaveApp - } + /// + /// 获取/设置 密码 + /// + [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 +{ + /// + /// 更改密码 + /// + ChangePassword, + + /// + /// 更改样式 + /// + ChangeTheme, + + /// + /// 更改显示名称 + /// + ChangeDisplayName, + + /// + /// 审批用户 + /// + ApproveUser, + + /// + /// 拒绝用户 + /// + RejectUser, + + /// + /// 保存默认应用 + /// + SaveApp } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj index a8e98d3d..cb3fe3fa 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdmin.DataAccess.PetaPoco.csproj @@ -1,13 +1,14 @@  - + + diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdminConventionMapper.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdminConventionMapper.cs index 0085f5d4..47ad5fbb 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdminConventionMapper.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/BootstrapAdminConventionMapper.cs @@ -2,73 +2,72 @@ using PetaPoco; using System.Reflection; -namespace BootstrapAdmin.DataAccess.PetaPoco +namespace BootstrapAdmin.DataAccess.PetaPoco; + +class BootstrapAdminConventionMapper : ConventionMapper { - class BootstrapAdminConventionMapper : ConventionMapper + /// + /// + /// + /// + /// + public override TableInfo GetTableInfo(Type pocoType) { - /// - /// - /// - /// - /// - public override TableInfo GetTableInfo(Type pocoType) + var ti = base.GetTableInfo(pocoType); + ti.AutoIncrement = true; + + // 支持 Oracle 数据库 + ti.SequenceName = $"SEQ_{ti.TableName.ToUpperInvariant()}_ID"; + + ti.TableName = pocoType.Name switch { - var ti = base.GetTableInfo(pocoType); - ti.AutoIncrement = true; - - // 支持 Oracle 数据库 - ti.SequenceName = $"SEQ_{ti.TableName.ToUpperInvariant()}_ID"; - - ti.TableName = pocoType.Name switch - { - _ => $"{pocoType.Name}s" - }; - return ti; - } - - /// - /// - /// - /// - /// - public override ColumnInfo GetColumnInfo(PropertyInfo pocoProperty) => pocoProperty.DeclaringType?.Name switch - { - nameof(Models.User) => GetUserColumnInfo(pocoProperty), - nameof(Models.Navigation) => GetNavigationColumnInfo(pocoProperty), - _ => base.GetColumnInfo(pocoProperty) + _ => $"{pocoType.Name}s" }; + return ti; + } - private ColumnInfo GetUserColumnInfo(PropertyInfo pocoProperty) - { - var ci = base.GetColumnInfo(pocoProperty); - var resultColumns = new List + /// + /// + /// + /// + /// + public override ColumnInfo GetColumnInfo(PropertyInfo pocoProperty) => pocoProperty.DeclaringType?.Name switch + { + nameof(Models.User) => GetUserColumnInfo(pocoProperty), + nameof(Models.Navigation) => GetNavigationColumnInfo(pocoProperty), + _ => base.GetColumnInfo(pocoProperty) + }; + + private ColumnInfo GetUserColumnInfo(PropertyInfo pocoProperty) + { + var ci = base.GetColumnInfo(pocoProperty); + var resultColumns = new List { nameof(Models.User.Period), nameof(Models.User.NewPassword), nameof(Models.User.ConfirmPassword), nameof(Models.User.IsReset) }; - ci.ResultColumn = resultColumns.Any(c => c == ci.ColumnName); - return ci; - } + ci.ResultColumn = resultColumns.Any(c => c == ci.ColumnName); + return ci; + } - private ColumnInfo GetNavigationColumnInfo(PropertyInfo pocoProperty) - { - var ci = base.GetColumnInfo(pocoProperty); - var resultColumns = new List + private ColumnInfo GetNavigationColumnInfo(PropertyInfo pocoProperty) + { + var ci = base.GetColumnInfo(pocoProperty); + var resultColumns = new List { nameof(Models.Navigation.HasChildren) }; - ci.ResultColumn = resultColumns.Any(c => c == ci.ColumnName); - return ci; - } - - public override Func GetFromDbConverter(PropertyInfo targetProperty, Type sourceType) => targetProperty.PropertyType.IsEnum && sourceType == typeof(string) - ? new StringToEnumConverter(targetProperty.PropertyType).ConvertFromDb - : base.GetFromDbConverter(targetProperty, sourceType); - - public override Func GetToDbConverter(PropertyInfo targetProperty) => targetProperty.PropertyType.IsEnum - ? new StringToEnumConverter(targetProperty.PropertyType).ConvertToDb - : base.GetToDbConverter(targetProperty); + ci.ResultColumn = resultColumns.Any(c => c == ci.ColumnName); + return ci; } + + public override Func GetFromDbConverter(PropertyInfo targetProperty, Type sourceType) => targetProperty.PropertyType.IsEnum && sourceType == typeof(string) + ? new StringToEnumConverter(targetProperty.PropertyType).ConvertFromDb + : base.GetFromDbConverter(targetProperty, sourceType); + + public override Func GetToDbConverter(PropertyInfo targetProperty) => targetProperty.PropertyType.IsEnum + ? new StringToEnumConverter(targetProperty.PropertyType).ConvertToDb + : base.GetToDbConverter(targetProperty); } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Coverters/StringToEnumConverter.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Coverters/StringToEnumConverter.cs index 25780b66..680477d6 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Coverters/StringToEnumConverter.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Coverters/StringToEnumConverter.cs @@ -1,59 +1,58 @@ -namespace BootstrapAdmin.DataAccess.PetaPoco.Coverters +namespace BootstrapAdmin.DataAccess.PetaPoco.Coverters; + +/// +/// 字符串转枚举转换器 +/// +public class StringToEnumConverter { + private Type TargetType { get; set; } + /// - /// 字符串转枚举转换器 + /// /// - public class StringToEnumConverter + /// + public StringToEnumConverter(Type targetType) => TargetType = targetType; + + /// + /// + /// + /// + /// + /// + public object? ConvertFromDb(object? value) { - private Type TargetType { get; set; } + if (value == null) throw new ArgumentNullException(nameof(value)); - /// - /// - /// - /// - public StringToEnumConverter(Type targetType) => TargetType = targetType; - - /// - /// - /// - /// - /// - /// - public object? ConvertFromDb(object? value) + object? ret; + if (value != null && Enum.TryParse(TargetType, value.ToString(), true, out var v)) { - if (value == null) throw new ArgumentNullException(nameof(value)); - - object? ret; - if (value != null && Enum.TryParse(TargetType, value.ToString(), true, out var v)) - { - ret = v; - } - else - { - throw new InvalidCastException($"{value} 无法转化为 {TargetType.Name} 成员"); - } - return ret; + ret = v; } - - /// - /// - /// - /// - /// - /// - public object? ConvertToDb(object? value) + else { - object? ret; - var field = value?.ToString(); - if (!string.IsNullOrEmpty(field) && Enum.IsDefined(TargetType, field)) - { - ret = field; - } - else - { - throw new InvalidCastException($"{TargetType.Name} 未定义 {field} 成员"); - } - return ret; + throw new InvalidCastException($"{value} 无法转化为 {TargetType.Name} 成员"); } + return ret; + } + + /// + /// + /// + /// + /// + /// + public object? ConvertToDb(object? value) + { + object? ret; + var field = value?.ToString(); + if (!string.IsNullOrEmpty(field) && Enum.IsDefined(TargetType, field)) + { + ret = field; + } + else + { + throw new InvalidCastException($"{TargetType.Name} 未定义 {field} 成员"); + } + return ret; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs index cad47014..b9f32044 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/DatabaseExtensions.cs @@ -7,176 +7,175 @@ using PetaPoco; using System.Linq.Expressions; using System.Reflection; -namespace BootstrapAdmin.Web.Extensions +namespace BootstrapAdmin.Web.Extensions; + +/// +/// +/// +public static class DatabaseExtensions { /// /// /// - public static class DatabaseExtensions + /// + /// + public static Task> FetchAsync(this IDatabase db, QueryPageOptions options) { - /// - /// - /// - /// - /// - public static Task> FetchAsync(this IDatabase db, QueryPageOptions options) + var sql = new Sql(); + + // 处理模糊查询 + if (options.Searchs.Any()) { - var sql = new Sql(); - - // 处理模糊查询 - if (options.Searchs.Any()) - { - var searchTextSql = new Sql(); - AnalysisExpression(options.Searchs.GetFilterLambda(FilterLogic.Or), db, searchTextSql); - sql.Append(searchTextSql.ToString().Replace("\nAND", "\nOR"), searchTextSql.Arguments); - } - - // 处理高级搜索与过滤 - var filters = options.Filters.Concat(options.CustomerSearchs); - if (filters.Any()) - { - AnalysisExpression(filters.GetFilterLambda(), db, sql); - } - - var sortName = options.SortName; - var sortOrder = options.SortOrder; - if (!string.IsNullOrEmpty(sortName) && sortOrder != SortOrder.Unset) - { - sql.OrderBy(sortOrder == SortOrder.Asc ? sortName : $"{sortName} desc"); - } - return db.FetchAsync(sql); + var searchTextSql = new Sql(); + AnalysisExpression(options.Searchs.GetFilterLambda(FilterLogic.Or), db, searchTextSql); + sql.Append(searchTextSql.ToString().Replace("\nAND", "\nOR"), searchTextSql.Arguments); } - /// - /// - /// - /// - /// - public static Task> PageAsync(this IDatabase db, QueryPageOptions options) + // 处理高级搜索与过滤 + var filters = options.Filters.Concat(options.CustomerSearchs); + if (filters.Any()) { - var sql = new Sql(); - - // 处理模糊查询 - if (options.Searchs.Any()) - { - var searchTextSql = new Sql(); - AnalysisExpression(options.Searchs.GetFilterLambda(FilterLogic.Or), db, searchTextSql); - sql.Append(searchTextSql.ToString().Replace("\nAND", "OR"), searchTextSql.Arguments); - } - - // 处理高级搜索与过滤 - var filters = options.Filters.Concat(options.CustomerSearchs); - if (filters.Any()) - { - AnalysisExpression(filters.GetFilterLambda(), db, sql); - } - - var sortName = options.SortName; - var sortOrder = options.SortOrder; - - if (!string.IsNullOrEmpty(sortName) && sortOrder != SortOrder.Unset) - { - sql.OrderBy(sortOrder == SortOrder.Asc ? sortName : $"{sortName} desc"); - } - return db.PageAsync(options.PageIndex, options.PageItems, sql); + AnalysisExpression(filters.GetFilterLambda(), db, sql); } - private static void AnalysisExpression(Expression expression, IDatabase db, Sql sql) + var sortName = options.SortName; + var sortOrder = options.SortOrder; + if (!string.IsNullOrEmpty(sortName) && sortOrder != SortOrder.Unset) { - switch (expression.NodeType) - { - case ExpressionType.Lambda: - if (expression is LambdaExpression exp) - { - AnalysisExpression(exp.Body, db, sql); - } - break; - case ExpressionType.AndAlso: - if (expression is BinaryExpression andExp) - { - AnalysisExpression(andExp.Left, db, sql); - AnalysisExpression(andExp.Right, db, sql); - } - break; - case ExpressionType.OrElse: - if (expression is BinaryExpression orExp) - { - AnalysisExpression(orExp.Left, db, sql); - AnalysisExpression(orExp.Right, db, sql); - } - break; - case ExpressionType.Call: - if (expression is MethodCallExpression callExp) - { - if (callExp.Method.Name == "Contains") - { - if (callExp.Object is MemberExpression callLeft) - { - var callColName = GetColumnName(callLeft.Member) ?? callLeft.Member.Name; - var p = (callExp.Arguments[0] as ConstantExpression)?.Value; - if (p != null) - { - sql.Where($"{db.Provider.EscapeSqlIdentifier(callColName)} like @0", $"%{p}%"); - } - } - } - } - break; - case ExpressionType.Equal: - case ExpressionType.NotEqual: - case ExpressionType.GreaterThan: - case ExpressionType.GreaterThanOrEqual: - case ExpressionType.LessThan: - case ExpressionType.LessThanOrEqual: - if (expression is BinaryExpression binaryExp) - { - MemberExpression? left = null; - if (binaryExp.Left is MethodCallExpression methodLeft && methodLeft.Method.Name == "ToString" && methodLeft.Object is MemberExpression p && p.Type.IsEnum) - { - // 枚举转字符串 - left = p; - } - else if (binaryExp.Left is MemberExpression m) - { - left = m; - } - - if (left != null) - { - // 查找 PetaPoco.Column 标签 - var columnName = GetColumnName(left.Member) ?? left.Member.Name; - - // 查找操作符右侧 - if (binaryExp.Right is ConstantExpression right) - { - var v = right.Value; - - if (v != null) - { - var val = v.GetType().IsEnum ? v.ToString() : v; - var operatorExp = GetOperatorExpression(expression); - sql.Where($"{db.Provider.EscapeSqlIdentifier(columnName)} {operatorExp} @0", val); - } - } - } - } - break; - } + sql.OrderBy(sortOrder == SortOrder.Asc ? sortName : $"{sortName} desc"); } - - private static string? GetColumnName(MemberInfo member) => member.CustomAttributes - .FirstOrDefault(i => i.AttributeType == typeof(ColumnAttribute))?.NamedArguments - .FirstOrDefault(i => i.MemberName == "Name").TypedValue.Value?.ToString(); - - private static string GetOperatorExpression(Expression expression) => expression.NodeType switch - { - ExpressionType.Equal => "=", - ExpressionType.NotEqual => "!=", - ExpressionType.GreaterThan => ">", - ExpressionType.GreaterThanOrEqual => ">=", - ExpressionType.LessThan => "<", - ExpressionType.LessThanOrEqual => "<=", - _ => "" - }; + return db.FetchAsync(sql); } + + /// + /// + /// + /// + /// + public static Task> PageAsync(this IDatabase db, QueryPageOptions options) + { + var sql = new Sql(); + + // 处理模糊查询 + if (options.Searchs.Any()) + { + var searchTextSql = new Sql(); + AnalysisExpression(options.Searchs.GetFilterLambda(FilterLogic.Or), db, searchTextSql); + sql.Append(searchTextSql.ToString().Replace("\nAND", "OR"), searchTextSql.Arguments); + } + + // 处理高级搜索与过滤 + var filters = options.Filters.Concat(options.CustomerSearchs); + if (filters.Any()) + { + AnalysisExpression(filters.GetFilterLambda(), db, sql); + } + + var sortName = options.SortName; + var sortOrder = options.SortOrder; + + if (!string.IsNullOrEmpty(sortName) && sortOrder != SortOrder.Unset) + { + sql.OrderBy(sortOrder == SortOrder.Asc ? sortName : $"{sortName} desc"); + } + return db.PageAsync(options.PageIndex, options.PageItems, sql); + } + + private static void AnalysisExpression(Expression expression, IDatabase db, Sql sql) + { + switch (expression.NodeType) + { + case ExpressionType.Lambda: + if (expression is LambdaExpression exp) + { + AnalysisExpression(exp.Body, db, sql); + } + break; + case ExpressionType.AndAlso: + if (expression is BinaryExpression andExp) + { + AnalysisExpression(andExp.Left, db, sql); + AnalysisExpression(andExp.Right, db, sql); + } + break; + case ExpressionType.OrElse: + if (expression is BinaryExpression orExp) + { + AnalysisExpression(orExp.Left, db, sql); + AnalysisExpression(orExp.Right, db, sql); + } + break; + case ExpressionType.Call: + if (expression is MethodCallExpression callExp) + { + if (callExp.Method.Name == "Contains") + { + if (callExp.Object is MemberExpression callLeft) + { + var callColName = GetColumnName(callLeft.Member) ?? callLeft.Member.Name; + var p = (callExp.Arguments[0] as ConstantExpression)?.Value; + if (p != null) + { + sql.Where($"{db.Provider.EscapeSqlIdentifier(callColName)} like @0", $"%{p}%"); + } + } + } + } + break; + case ExpressionType.Equal: + case ExpressionType.NotEqual: + case ExpressionType.GreaterThan: + case ExpressionType.GreaterThanOrEqual: + case ExpressionType.LessThan: + case ExpressionType.LessThanOrEqual: + if (expression is BinaryExpression binaryExp) + { + MemberExpression? left = null; + if (binaryExp.Left is MethodCallExpression methodLeft && methodLeft.Method.Name == "ToString" && methodLeft.Object is MemberExpression p && p.Type.IsEnum) + { + // 枚举转字符串 + left = p; + } + else if (binaryExp.Left is MemberExpression m) + { + left = m; + } + + if (left != null) + { + // 查找 PetaPoco.Column 标签 + var columnName = GetColumnName(left.Member) ?? left.Member.Name; + + // 查找操作符右侧 + if (binaryExp.Right is ConstantExpression right) + { + var v = right.Value; + + if (v != null) + { + var val = v.GetType().IsEnum ? v.ToString() : v; + var operatorExp = GetOperatorExpression(expression); + sql.Where($"{db.Provider.EscapeSqlIdentifier(columnName)} {operatorExp} @0", val); + } + } + } + } + break; + } + } + + private static string? GetColumnName(MemberInfo member) => member.CustomAttributes + .FirstOrDefault(i => i.AttributeType == typeof(ColumnAttribute))?.NamedArguments + .FirstOrDefault(i => i.MemberName == "Name").TypedValue.Value?.ToString(); + + private static string GetOperatorExpression(Expression expression) => expression.NodeType switch + { + ExpressionType.Equal => "=", + ExpressionType.NotEqual => "!=", + ExpressionType.GreaterThan => ">", + ExpressionType.GreaterThanOrEqual => ">=", + ExpressionType.LessThan => "<", + ExpressionType.LessThanOrEqual => "<=", + _ => "" + }; } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs index 16659b3e..ce559a97 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs @@ -14,66 +14,65 @@ using System.Collections.Specialized; using System.Data.Common; using System.Text; -namespace Microsoft.Extensions.DependencyInjection +namespace Microsoft.Extensions.DependencyInjection; + +/// +/// +/// +public static class ServicesExtensions { /// /// /// - public static class ServicesExtensions + /// + /// + public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services) { - /// - /// - /// - /// - /// - public static IServiceCollection AddPetaPocoDataAccessServices(this IServiceCollection services) + services.TryAddSingleton(provider => { - services.TryAddSingleton(provider => - { //TODO: 后期改造成自定适配 var configuration = provider.GetRequiredService(); - var connString = configuration.GetConnectionString("bb"); - var db = new Database(connString, new BootstrapAdminConventionMapper()); + var connString = configuration.GetConnectionString("bb"); + var db = new Database(connString, new BootstrapAdminConventionMapper()); - var logger = provider.GetRequiredService>(); - db.ExceptionThrown += (sender, e) => + var logger = provider.GetRequiredService>(); + db.ExceptionThrown += (sender, e) => + { + var message = e.Exception.Format(new NameValueCollection() { - var message = e.Exception.Format(new NameValueCollection() - { - [nameof(db.LastCommand)] = db.LastCommand, - [nameof(db.LastArgs)] = string.Join(",", db.LastArgs) - }); - logger.LogInformation(message); - }; - var env = provider.GetRequiredService(); - if (env.IsDevelopment()) + [nameof(db.LastCommand)] = db.LastCommand, + [nameof(db.LastArgs)] = string.Join(",", db.LastArgs) + }); + logger.LogInformation(message); + }; + var env = provider.GetRequiredService(); + if (env.IsDevelopment()) + { + db.CommandExecuted += (sender, args) => { - db.CommandExecuted += (sender, args) => + var parameters = new StringBuilder(); + foreach (DbParameter p in args.Command.Parameters) { - var parameters = new StringBuilder(); - foreach (DbParameter p in args.Command.Parameters) - { - parameters.AppendFormat("{0}: {1} ", p.ParameterName, p.Value); - } - logger.LogInformation(args.Command.CommandText); - logger.LogInformation(parameters.ToString()); - }; + parameters.AppendFormat("{0}: {1} ", p.ParameterName, p.Value); + } + logger.LogInformation(args.Command.CommandText); + logger.LogInformation(parameters.ToString()); }; - return db; - }); + }; + return db; + }); - // 增加数据服务 - services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>)); + // 增加数据服务 + services.AddSingleton(typeof(IDataService<>), typeof(DefaultDataService<>)); - // 增加业务服务 - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); - return services; - } + // 增加业务服务 + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + return services; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/Database.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/Database.cs index 22db9234..d25a6c4b 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/Database.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/Database.cs @@ -1,13 +1,12 @@ using PetaPoco; -namespace BootstrapAdmin.DataAccess.PetaPoco.Services +namespace BootstrapAdmin.DataAccess.PetaPoco.Services; + +abstract class BaseDatabase { - abstract class BaseDatabase - { - /// - /// - /// - [NotNull] - protected IDatabase? Database { get; set; } - } + /// + /// + /// + [NotNull] + protected IDatabase? Database { get; set; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DefaultDataService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DefaultDataService.cs index 710979a1..2c4c9fe3 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DefaultDataService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DefaultDataService.cs @@ -7,80 +7,79 @@ using BootstrapBlazor.Components; using PetaPoco; using PetaPoco.Extensions; -namespace BootstrapBlazor.DataAcces.PetaPoco.Services +namespace BootstrapBlazor.DataAcces.PetaPoco.Services; + +/// +/// PetaPoco ORM 的 IDataService 接口实现 +/// +class DefaultDataService : DataServiceBase where TModel : class, new() { + private IDatabase Database { get; } + /// - /// PetaPoco ORM 的 IDataService 接口实现 + /// 构造函数 /// - class DefaultDataService : DataServiceBase where TModel : class, new() + public DefaultDataService(IDatabase db) => Database = db; + + /// + /// 删除方法 + /// + /// + /// + public override Task DeleteAsync(IEnumerable models) { - private IDatabase Database { get; } + // 通过模型获取主键列数据 + // 支持批量删除 + Database.DeleteBatch(models); + return Task.FromResult(true); + } - /// - /// 构造函数 - /// - public DefaultDataService(IDatabase db) => Database = db; - - /// - /// 删除方法 - /// - /// - /// - public override Task DeleteAsync(IEnumerable models) + /// + /// 保存方法 + /// + /// + /// + /// + public override async Task SaveAsync(TModel model, ItemChangedType changedType) + { + if (changedType == ItemChangedType.Add) { - // 通过模型获取主键列数据 - // 支持批量删除 - Database.DeleteBatch(models); - return Task.FromResult(true); + await Database.InsertAsync(model); } - - /// - /// 保存方法 - /// - /// - /// - /// - public override async Task SaveAsync(TModel model, ItemChangedType changedType) + else { - if (changedType == ItemChangedType.Add) - { - await Database.InsertAsync(model); - } - else - { - await Database.UpdateAsync(model); - } - return true; + await Database.UpdateAsync(model); } + return true; + } - /// - /// 查询方法 - /// - /// - /// - public override async Task> QueryAsync(QueryPageOptions option) + /// + /// 查询方法 + /// + /// + /// + public override async Task> QueryAsync(QueryPageOptions option) + { + var ret = new QueryData() { - var ret = new QueryData() - { - IsSorted = true, - IsFiltered = true, - IsSearch = true - }; + IsSorted = true, + IsFiltered = true, + IsSearch = true + }; - if (option.IsPage) - { - var items = await Database.PageAsync(option); + if (option.IsPage) + { + var items = await Database.PageAsync(option); - ret.TotalCount = Convert.ToInt32(items.TotalItems); - ret.Items = items.Items; - } - else - { - var items = await Database.FetchAsync(option); - ret.TotalCount = items.Count; - ret.Items = items; - } - return ret; + ret.TotalCount = Convert.ToInt32(items.TotalItems); + ret.Items = items.Items; } + else + { + var items = await Database.FetchAsync(option); + ret.TotalCount = items.Count; + ret.Items = items; + } + return ret; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/LoginService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/LoginService.cs index 599e1792..4701653e 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/LoginService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/LoginService.cs @@ -5,20 +5,19 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BootstrapAdmin.DataAccess.PetaPoco.Services +namespace BootstrapAdmin.DataAccess.PetaPoco.Services; + +class LoginService : ILogin { - class LoginService : ILogin + /// + /// + /// + /// + /// + /// + /// + public Task Log(string userName, bool result) { - /// - /// - /// - /// - /// - /// - /// - public Task Log(string userName, bool result) - { - return Task.FromResult(true); - } + return Task.FromResult(true); } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs index fa287448..d2bd640b 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/NavigationService.cs @@ -2,60 +2,59 @@ using BootstrapAdmin.Web.Core; using PetaPoco; -namespace BootstrapAdmin.DataAccess.PetaPoco.Services +namespace BootstrapAdmin.DataAccess.PetaPoco.Services; + +/// +/// +/// +class NavigationService : BaseDatabase, INavigation { /// /// /// - class NavigationService : BaseDatabase, INavigation + /// + public NavigationService(IDatabase db) => Database = db; + + /// + /// 获得指定用户名可访问的所有菜单集合 + /// + /// 当前用户名 + /// 未层次化的菜单集合 + public List GetAllMenus(string userName) { - /// - /// - /// - /// - public NavigationService(IDatabase db) => Database = db; + var order = Database.Provider.EscapeSqlIdentifier("Order"); + return Database.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 'System' 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 ORDER BY n.Application, n.{order}", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); + } - /// - /// 获得指定用户名可访问的所有菜单集合 - /// - /// 当前用户名 - /// 未层次化的菜单集合 - public List GetAllMenus(string userName) + /// + /// + /// + /// + /// + public List GetMenusByRoleId(string? roleId) => Database.Fetch("select NavigationID from NavigationRole where RoleID = @0", roleId); + + /// + /// + /// + /// + /// + /// + public bool SaveMenusByRoleId(string? roleId, List menuIds) + { + var ret = false; + try { - var order = Database.Provider.EscapeSqlIdentifier("Order"); - return Database.Fetch($"select n.ID, n.ParentId, n.Name, n.{order}, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 'System' 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 ORDER BY n.Application, n.{order}", new { UserName = userName, Category = "菜单", RoleName = "Administrators" }); + Database.BeginTransaction(); + Database.Execute("delete from NavigationRole where RoleID = @0", roleId); + Database.InsertBatch("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId })); + Database.CompleteTransaction(); + ret = true; } - - /// - /// - /// - /// - /// - public List GetMenusByRoleId(string? roleId) => Database.Fetch("select NavigationID from NavigationRole where RoleID = @0", roleId); - - /// - /// - /// - /// - /// - /// - public bool SaveMenusByRoleId(string? roleId, List menuIds) + catch (Exception) { - var ret = false; - try - { - Database.BeginTransaction(); - Database.Execute("delete from NavigationRole where RoleID = @0", roleId); - Database.InsertBatch("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId })); - Database.CompleteTransaction(); - ret = true; - } - catch (Exception) - { - Database.AbortTransaction(); - throw; - } - return ret; + Database.AbortTransaction(); + throw; } + return ret; } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/AdminService.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/AdminService.cs index 3b4da237..5acae827 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/AdminService.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/AdminService.cs @@ -1,57 +1,56 @@ using Bootstrap.Security.Blazor; using BootstrapAdmin.Web.Core; -namespace BootstrapAdmin.Web.Services +namespace BootstrapAdmin.Web.Services; + +/// +/// +/// +public class AdminService : IBootstrapAdminService { + private IUser User { get; set; } + + private INavigation Navigations { get; set; } + /// /// /// - public class AdminService : IBootstrapAdminService + /// + /// + public AdminService(IUser user, INavigation navigations) { - private IUser User { get; set; } + User = user; + Navigations = navigations; + } - private INavigation Navigations { get; set; } + /// + /// 通过用户名获取角色集合方法 + /// + /// + /// + public List GetRoles(string userName) => User.GetRoles(userName); - /// - /// - /// - /// - /// - public AdminService(IUser user, INavigation navigations) + /// + /// 通过用户名获取授权 App 集合方法 + /// + /// + /// + public List GetApps(string userName) => User.GetApps(userName); + + /// + /// 通过用户名检查当前请求 Url 是否已授权方法 + /// + /// + /// + /// + public Task AuhorizingNavigation(string userName, string url) + { + var ret = false; + if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)) { - User = user; - Navigations = navigations; - } - - /// - /// 通过用户名获取角色集合方法 - /// - /// - /// - public List GetRoles(string userName) => User.GetRoles(userName); - - /// - /// 通过用户名获取授权 App 集合方法 - /// - /// - /// - public List GetApps(string userName) => User.GetApps(userName); - - /// - /// 通过用户名检查当前请求 Url 是否已授权方法 - /// - /// - /// - /// - public Task AuhorizingNavigation(string userName, string url) - { - var ret = false; - if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out var uri)) - { - ret = Navigations.GetAllMenus(userName) - .Any(m => m.Url.Contains(uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)); - } - return Task.FromResult(ret); + ret = Navigations.GetAllMenus(userName) + .Any(m => m.Url.Contains(uri.AbsolutePath, StringComparison.OrdinalIgnoreCase)); } + return Task.FromResult(ret); } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs index 936b2e2a..62d62365 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs @@ -1,64 +1,63 @@ -namespace BootstrapAdmin.Web.Core +namespace BootstrapAdmin.Web.Core; + +/// +/// Dict 字典表接口 +/// +public interface IDict { /// - /// Dict 字典表接口 + /// 获得 配置所有的 App 集合 /// - public interface IDict - { - /// - /// 获得 配置所有的 App 集合 - /// - /// - Dictionary GetApps(); + /// + Dictionary GetApps(); - /// - /// 获得 配置所有的登录页集合 - /// - /// - Dictionary GetLogins(); + /// + /// 获得 配置所有的登录页集合 + /// + /// + Dictionary GetLogins(); - /// - /// 获得 配置所有的主题集合 - /// - /// - Dictionary GetThemes(); + /// + /// 获得 配置所有的主题集合 + /// + /// + Dictionary GetThemes(); - /// - /// 获取当前系统配置是否为演示模式 - /// - /// - bool IsDemo(); + /// + /// 获取当前系统配置是否为演示模式 + /// + /// + bool IsDemo(); - /// - /// 保存当前网站是否为演示系统 - /// - /// - /// - bool SaveDemo(bool isDemo); + /// + /// 保存当前网站是否为演示系统 + /// + /// + /// + bool SaveDemo(bool isDemo); - /// - /// 保存健康检查 - /// - /// - bool SaveHealthCheck(bool enable = true); + /// + /// 保存健康检查 + /// + /// + bool SaveHealthCheck(bool enable = true); - /// - /// 获得当前授权码是否有效可更改网站设置 - /// - /// - /// - bool AuthenticateDemo(string code); + /// + /// 获得当前授权码是否有效可更改网站设置 + /// + /// + /// + bool AuthenticateDemo(string code); - /// - /// 获取 站点 Title 配置信息 - /// - /// - string GetWebTitle(); + /// + /// 获取 站点 Title 配置信息 + /// + /// + string GetWebTitle(); - /// - /// 获取站点 Footer 配置信息 - /// - /// - string GetWebFooter(); - } + /// + /// 获取站点 Footer 配置信息 + /// + /// + string GetWebFooter(); } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/ILogin.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/ILogin.cs index 5a6f8fb2..d9bb8b54 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/ILogin.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/ILogin.cs @@ -1,16 +1,15 @@ -namespace BootstrapAdmin.Web.Core +namespace BootstrapAdmin.Web.Core; + +/// +/// +/// +public interface ILogin { /// /// /// - public interface ILogin - { - /// - /// - /// - /// - /// - /// - Task Log(string userName, bool result); - } + /// + /// + /// + Task Log(string userName, bool result); } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs index 27b2961b..ec9d3206 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/INavigation.cs @@ -1,30 +1,29 @@ using BootstrapAdmin.DataAccess.Models; -namespace BootstrapAdmin.Web.Core +namespace BootstrapAdmin.Web.Core; + +/// +/// +/// +public interface INavigation { /// /// /// - public interface INavigation - { - /// - /// - /// - /// - List GetAllMenus(string userName); + /// + List GetAllMenus(string userName); - /// - /// - /// - /// - /// - List GetMenusByRoleId(string? roleId); + /// + /// + /// + /// + /// + List GetMenusByRoleId(string? roleId); - /// - /// - /// - /// - /// - bool SaveMenusByRoleId(string? roleId, List menuIds); - } + /// + /// + /// + /// + /// + bool SaveMenusByRoleId(string? roleId, List menuIds); }