feat: 更新 IRole 接口方法
This commit is contained in:
parent
30614bd223
commit
6029e86072
|
@ -2,10 +2,10 @@
|
|||
using BootstrapAdmin.Web.Core;
|
||||
using PetaPoco;
|
||||
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
||||
namespace BootstrapAdmin.DataAccess.PetaPoco.Services;
|
||||
|
||||
class RoleService : BaseDatabase, IRole
|
||||
{
|
||||
class RoleService : BaseDatabase, IRole
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
@ -21,26 +21,24 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public List<string> GetUsersByRoleId(string? id) => Database.Fetch<string>("select UserID from UserRole where RoleID = @0", id);
|
||||
public List<string> GetRolesByGroupId(string? groupId) => Database.Fetch<string>("select RoleID from RoleGroup where GroupID = @0", groupId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
public bool SaveUsersByRoleId(string? id, IEnumerable<string> userIds)
|
||||
public bool SaveRolesByGroupId(string? groupId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
{
|
||||
Database.BeginTransaction();
|
||||
Database.Execute("delete from UserRole where RoleID = @0", id);
|
||||
Database.InsertBatch("UserRole", userIds.Select(g => new { UserID = g, RoleID = id }));
|
||||
Database.Execute("delete from RoleGroup where GroupID = @0", groupId);
|
||||
Database.InsertBatch("RoleGroup", roleIds.Select(g => new { RoleID = g, GroupID = groupId }));
|
||||
Database.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
|
@ -51,5 +49,36 @@ namespace BootstrapAdmin.DataAccess.PetaPoco.Services
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public List<string> GetRolesByUserId(string? userId) => Database.Fetch<string>("select RoleID from UserRole where UserID = @0", userId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
public bool SaveRolesByUserId(string? userId, IEnumerable<string> roleIds)
|
||||
{
|
||||
var ret = false;
|
||||
try
|
||||
{
|
||||
Database.BeginTransaction();
|
||||
Database.Execute("delete from UserRole where UserID = @0", userId);
|
||||
Database.InsertBatch("UserRole", roleIds.Select(g => new { RoleID = g, UserID = userId }));
|
||||
Database.CompleteTransaction();
|
||||
ret = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Database.AbortTransaction();
|
||||
throw;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,15 +16,30 @@ public interface IRole
|
|||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
List<string> GetUsersByRoleId(string? id);
|
||||
List<string> GetRolesByGroupId(string? userId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveUsersByRoleId(string? id, IEnumerable<string> values);
|
||||
bool SaveRolesByGroupId(string? groupId, IEnumerable<string> roleIds);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
List<string> GetRolesByUserId(string? groupId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="roleIds"></param>
|
||||
/// <returns></returns>
|
||||
bool SaveRolesByUserId(string? groupId, IEnumerable<string> roleIds);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using BootstrapAdmin.Web.Components;
|
||||
namespace BootstrapAdmin.Web.Pages.Admin;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Admin
|
||||
public partial class Menus
|
||||
{
|
||||
public partial class Menus
|
||||
{
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private DialogService? DialogService { get; set; }
|
||||
|
@ -17,5 +15,4 @@ namespace BootstrapAdmin.Web.Pages.Admin
|
|||
|
||||
await DialogService.Show(option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using BootstrapAdmin.DataAccess.Models;
|
||||
using BootstrapAdmin.Web.Components;
|
||||
using BootstrapAdmin.Web.Core;
|
||||
using BootstrapAdmin.Web.Extensions;
|
||||
|
||||
namespace BootstrapAdmin.Web.Pages.Admin
|
||||
{
|
||||
|
@ -19,6 +20,11 @@ namespace BootstrapAdmin.Web.Pages.Admin
|
|||
[Inject]
|
||||
[NotNull]
|
||||
private IGroup? GroupService { get; set; }
|
||||
|
||||
[Inject]
|
||||
[NotNull]
|
||||
private IRole? RoleService { get; set; }
|
||||
|
||||
private async Task OnAssignmentGroups(User user)
|
||||
{
|
||||
var groups = GroupService.GetAll().ToSelectedItemList();
|
||||
|
@ -33,12 +39,14 @@ namespace BootstrapAdmin.Web.Pages.Admin
|
|||
|
||||
private async Task OnAssignmentRoles(User user)
|
||||
{
|
||||
var option = new DialogOption()
|
||||
{
|
||||
Title = $"分配角色 - {user}",
|
||||
};
|
||||
var groups = RoleService.GetAll().ToSelectedItemList();
|
||||
var values = RoleService.GetRolesByUserId(user.Id);
|
||||
|
||||
await DialogService.Show(option);
|
||||
await DialogService.ShowAssignmentDialog($"分配角色 - {user}", groups, values, () =>
|
||||
{
|
||||
var ret = RoleService.SaveRolesByUserId(user.Id, values);
|
||||
return Task.FromResult(ret);
|
||||
}, ToastService);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue