|
|
@ -1,15 +1,20 @@ |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
|
|
|
using System.ComponentModel.DataAnnotations; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Volo.Abp.AspNetCore.Mvc.RazorPages; |
|
|
using Volo.Abp.AspNetCore.Mvc.RazorPages; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.Identity.Web.Pages.Identity.Users |
|
|
namespace Volo.Abp.Identity.Web.Pages.Identity.Users |
|
|
{ |
|
|
{ |
|
|
public class EditModalModel : AbpPageModel |
|
|
public class EditModalModel : AbpPageModel |
|
|
{ |
|
|
{ |
|
|
public IdentityUserDto EditingUser { get; set; } |
|
|
[BindProperty] |
|
|
public IdentityUserRoleDto[] Roles { get; set; } |
|
|
public UserInfoViewModel UserInfo { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[BindProperty] |
|
|
|
|
|
public AssignedRoleViewModel[] Roles { get; set; } |
|
|
|
|
|
|
|
|
private readonly IIdentityUserAppService _identityUserAppService; |
|
|
private readonly IIdentityUserAppService _identityUserAppService; |
|
|
private readonly IIdentityRoleAppService _identityRoleAppService; |
|
|
private readonly IIdentityRoleAppService _identityRoleAppService; |
|
|
@ -22,17 +27,25 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users |
|
|
|
|
|
|
|
|
public async Task OnGetAsync(Guid id) |
|
|
public async Task OnGetAsync(Guid id) |
|
|
{ |
|
|
{ |
|
|
EditingUser = await _identityUserAppService.GetAsync(id); |
|
|
UserInfo = ObjectMapper.Map<IdentityUserDto, UserInfoViewModel>(await _identityUserAppService.GetAsync(id)); |
|
|
Roles = ObjectMapper.Map<List<IdentityRoleDto>, IdentityUserRoleDto[]>( |
|
|
|
|
|
|
|
|
Roles = ObjectMapper.Map<List<IdentityRoleDto>, AssignedRoleViewModel[]>( |
|
|
await _identityRoleAppService.GetAllListAsync() |
|
|
await _identityRoleAppService.GetAllListAsync() |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
await SetAssignedRoles(); |
|
|
await SetAssignedRoles(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task OnPostAsync() |
|
|
|
|
|
{ |
|
|
|
|
|
var input = ObjectMapper.Map<UserInfoViewModel, IdentityUserUpdateDto>(UserInfo); |
|
|
|
|
|
input.RoleNames = Roles.Where(r => r.IsAssigned).Select(r => r.Name).ToArray(); |
|
|
|
|
|
await _identityUserAppService.UpdateAsync(UserInfo.Id, input); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private async Task SetAssignedRoles() |
|
|
private async Task SetAssignedRoles() |
|
|
{ |
|
|
{ |
|
|
var userRoleNames = (await _identityUserAppService.GetRolesAsync(EditingUser.Id)).Items.Select(r => r.Name).ToList(); |
|
|
var userRoleNames = (await _identityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList(); |
|
|
foreach (var role in Roles) |
|
|
foreach (var role in Roles) |
|
|
{ |
|
|
{ |
|
|
if (userRoleNames.Contains(role.Name)) |
|
|
if (userRoleNames.Contains(role.Name)) |
|
|
@ -41,5 +54,31 @@ namespace Volo.Abp.Identity.Web.Pages.Identity.Users |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class UserInfoViewModel |
|
|
|
|
|
{ |
|
|
|
|
|
[HiddenInput] |
|
|
|
|
|
public Guid Id { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[Required] |
|
|
|
|
|
[MaxLength(IdentityUserConsts.MaxUserNameLength)] |
|
|
|
|
|
public string UserName { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[MaxLength(IdentityUserConsts.MaxEmailLength)] |
|
|
|
|
|
[EmailAddress] |
|
|
|
|
|
public string Email { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
[MaxLength(IdentityUserConsts.MaxPhoneNumberLength)] |
|
|
|
|
|
public string PhoneNumber { get; set; } |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class AssignedRoleViewModel |
|
|
|
|
|
{ |
|
|
|
|
|
[Required] |
|
|
|
|
|
[HiddenInput] |
|
|
|
|
|
public string Name { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
public bool IsAssigned { get; set; } |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |