diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs index a7bf2255..a91fe323 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.EFCore/Services/DictsService.cs @@ -1,9 +1,15 @@ using BootstrapAdmin.Web.Core; +using BootstrapBlazor.Components; namespace BootstrapAdmin.DataAccess.EFCore.Services { class DictsService : IDict { + public List GetApps() + { + throw new NotImplementedException(); + } + public string GetWebFooter() { throw new NotImplementedException(); diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs index 1e7be86f..7b09bd26 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Extensions/ServicesExtensions.cs @@ -40,6 +40,7 @@ namespace Microsoft.Extensions.DependencyInjection services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); return services; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs new file mode 100644 index 00000000..e6955dc3 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/AppService.cs @@ -0,0 +1,40 @@ +using BootstrapAdmin.DataAccess.Models; +using BootstrapAdmin.Web.Core; +using BootstrapBlazor.Components; +using PetaPoco; + +namespace BootstrapAdmin.DataAccess.PetaPoco.Services; + +class AppService : BaseDatabase, IApp +{ + private List Apps { get; set; } + + public AppService(IDatabase db, IDict dict) + { + Database = db; + Apps = dict.GetApps(); + } + + public List GetAll() => Apps; + + public List GetAppsByRoleId(string? roleId) => Database.Fetch("select AppID from RoleApp where RoleID = @0", roleId); + + public bool SaveAppsByRoleId(string? roleId, IEnumerable appIds) + { + var ret = false; + try + { + Database.BeginTransaction(); + Database.Execute("delete from RoleApp where RoleID = @0", roleId); + Database.InsertBatch("RoleApp", appIds.Select(g => new { AppID = g, RoleID = roleId })); + Database.CompleteTransaction(); + ret = true; + } + catch (Exception) + { + Database.AbortTransaction(); + throw; + } + return ret; + } +} diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs index 84cf6b1e..86603fc5 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/DictService.cs @@ -1,59 +1,65 @@ using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.Web.Core; +using BootstrapBlazor.Components; using Microsoft.Extensions.Configuration; using PetaPoco; -namespace BootstrapAdmin.DataAccess.PetaPoco.Services +namespace BootstrapAdmin.DataAccess.PetaPoco.Services; + +class DictService : BaseDatabase, IDict { - class DictService : BaseDatabase, IDict + private string AppId { get; set; } + + /// + /// + /// + /// + /// + public DictService(IDatabase db, IConfiguration configuration) { - private string AppId { get; set; } + Database = db; + AppId = configuration.GetValue("AppId", "BA"); + } - /// - /// - /// - /// - /// - public DictService(IDatabase db, IConfiguration configuration) + private List GetAll() => Database.Fetch(); + + public List GetApps() + { + var dicts = GetAll(); + return dicts.Where(d => d.Category == "应用程序").Select(d => new SelectedItem(d.Code, d.Name)).ToList(); + } + + /// + /// 获取 站点 Title 配置信息 + /// + /// + public string GetWebTitle() + { + var dicts = GetAll(); + var title = "网站标题"; + var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name; + if (!string.IsNullOrEmpty(name)) { - Database = db; - AppId = configuration.GetValue("AppId", "BA"); + var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站标题") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站标题"); + title = dict?.Code ?? "网站标题"; } + return title; + } - private List GetAll() => Database.Fetch(); - - /// - /// 获取 站点 Title 配置信息 - /// - /// - public string GetWebTitle() + /// + /// 获取站点 Footer 配置信息 + /// + /// + public string GetWebFooter() + { + var dicts = GetAll(); + var title = "网站页脚"; + var name = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == AppId)?.Name; + if (!string.IsNullOrEmpty(name)) { - 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; - } - - /// - /// 获取站点 Footer 配置信息 - /// - /// - 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; + var dict = dicts.FirstOrDefault(d => d.Category == name && d.Name == "网站页脚") ?? dicts.FirstOrDefault(d => d.Category == "网站设置" && d.Name == "网站页脚"); + title = dict?.Code ?? "网站标题"; } + return title; } } diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs index e6e8af40..6e685c13 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs @@ -55,7 +55,7 @@ class GroupService : BaseDatabase, IGroup /// /// /// - public List GetGroupsByRoleId(string? roleId) => Database.Fetch("select GroupID from RoleGroup where RoleGroup = @0", roleId); + public List GetGroupsByRoleId(string? roleId) => Database.Fetch("select GroupID from RoleGroup where RoleID = @0", roleId); /// /// @@ -69,7 +69,7 @@ class GroupService : BaseDatabase, IGroup try { Database.BeginTransaction(); - Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId); + Database.Execute("delete from RoleGroup where RoleID = @0", roleId); Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId })); Database.CompleteTransaction(); ret = true; diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IApp.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IApp.cs new file mode 100644 index 00000000..498e1e84 --- /dev/null +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IApp.cs @@ -0,0 +1,30 @@ +using BootstrapBlazor.Components; + +namespace BootstrapAdmin.Web.Core; + +/// +/// +/// +public interface IApp +{ + /// + /// 获得所有用户 + /// + /// + List GetAll(); + + /// + /// + /// + /// + /// + List GetAppsByRoleId(string? roleId); + + /// + /// + /// + /// + /// + /// + bool SaveAppsByRoleId(string? roleId, IEnumerable appIds); +} diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs index cdd7e73c..0387e8a5 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IDict.cs @@ -1,10 +1,14 @@ -namespace BootstrapAdmin.Web.Core +using BootstrapBlazor.Components; + +namespace BootstrapAdmin.Web.Core { /// /// Dict 字典表接口 /// public interface IDict { + List GetApps(); + /// /// 获取 站点 Title 配置信息 /// diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs index 1ec27ab7..a08760e5 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs @@ -7,7 +7,6 @@ namespace BootstrapAdmin.Web.Core; /// public interface IGroup { - /// /// 获得所有用户 /// diff --git a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs index 7a5f037c..bba3dbf5 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs @@ -22,12 +22,16 @@ public partial class Roles [NotNull] private IUser? UserService { get; set; } + [Inject] + [NotNull] + private IApp? AppService { get; set; } + private async Task OnAssignmentUsers(Role role) { var users = UserService.GetAll().ToSelectedItemList(); var values = UserService.GetUsersByRoleId(role.Id); - await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", users, values, () => + await DialogService.ShowAssignmentDialog($"分配用户 - {role.RoleName}", users, values, () => { var ret = UserService.SaveUsersByRoleId(role.Id, values); return Task.FromResult(ret); @@ -58,12 +62,13 @@ public partial class Roles private async Task OnAssignmentApps(Role role) { - var option = new DialogOption() + var apps = AppService.GetAll(); + var values = AppService.GetAppsByRoleId(role.Id); + + await DialogService.ShowAssignmentDialog($"分配应用 - {role.RoleName}", apps, values, () => { - Title = $"分配应用 - {role}", - }; - - await DialogService.Show(option); + var ret = AppService.SaveAppsByRoleId(role.Id, values); + return Task.FromResult(ret); + }, ToastService); } - }