From f2095cac40175f50936fb2269d3aac458c34ee86 Mon Sep 17 00:00:00 2001 From: Argo-Tianyi Date: Tue, 21 Dec 2021 11:55:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E5=AF=B9=E9=83=A8=E9=97=A8=E6=8E=88=E6=9D=83=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/GroupService.cs | 32 +++++++++++++++++++ .../admin/BootstrapAdmin.Web.Core/IGroup.cs | 17 +++++++++- .../Pages/Admin/Roles.razor.cs | 22 ++++++++++--- 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs index 9e303072..039db795 100644 --- a/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs +++ b/src/blazor/admin/BootstrapAdmin.DataAccess.PetaPoco/Services/GroupService.cs @@ -49,5 +49,37 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services } return ret; } + + /// + /// + /// + /// + /// + public List GetGroupsByRoleId(string? roleId) => Database.Fetch("select GroupID from RoleGroup where RoleGroup = @0", roleId); + + /// + /// + /// + /// + /// + /// + public bool SaveGroupsByRoleId(string? roleId, IEnumerable groupIds) + { + var ret = false; + try + { + Database.BeginTransaction(); + Database.Execute("delete from RoleGroup where RoleGroup = @0", roleId); + Database.InsertBatch("RoleGroup", groupIds.Select(g => new { GroupID = g, RoleID = roleId })); + Database.CompleteTransaction(); + ret = true; + } + catch (Exception) + { + Database.AbortTransaction(); + throw; + } + return ret; + } } } diff --git a/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs b/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs index fc060afd..1ec27ab7 100644 --- a/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs +++ b/src/blazor/admin/BootstrapAdmin.Web.Core/IGroup.cs @@ -25,7 +25,22 @@ public interface IGroup /// /// /// - /// + /// /// bool SaveGroupsByUserId(string? userId, IEnumerable groupIds); + + /// + /// + /// + /// + /// + List GetGroupsByRoleId(string? roleId); + + /// + /// + /// + /// + /// + /// + bool SaveGroupsByRoleId(string? roleId, IEnumerable groupIds); } 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 83c942f2..52e34231 100644 --- a/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs +++ b/src/blazor/admin/BootstrapAdmin.Web/Pages/Admin/Roles.razor.cs @@ -1,5 +1,7 @@ using BootstrapAdmin.DataAccess.Models; using BootstrapAdmin.Web.Components; +using BootstrapAdmin.Web.Core; +using BootstrapAdmin.Web.Extensions; namespace BootstrapAdmin.Web.Pages.Admin { @@ -9,6 +11,14 @@ namespace BootstrapAdmin.Web.Pages.Admin [NotNull] private DialogService? DialogService { get; set; } + [Inject] + [NotNull] + private ToastService? ToastService { get; set; } + + [Inject] + [NotNull] + private IGroup? GroupService { get; set; } + private async Task OnAssignmentUsers(Role role) { var option = new DialogOption() @@ -21,12 +31,14 @@ namespace BootstrapAdmin.Web.Pages.Admin private async Task OnAssignmentGroups(Role role) { - var option = new DialogOption() - { - Title = $"分配部门 - {role}", - }; + var groups = GroupService.GetAll().ToSelectedItemList(); + var values = GroupService.GetGroupsByRoleId(role.Id); - await DialogService.Show(option); + await DialogService.ShowAssignmentDialog($"分配部门 - {role.RoleName}", groups, values, () => + { + var ret = GroupService.SaveGroupsByRoleId(role.Id, values); + return Task.FromResult(ret); + }, ToastService); } private async Task OnAssignmentMenus(Role role)