Browse Source

Merge pull request #129 from aspnetzero/user-crud

User crud
pull/138/head
Halil İbrahim Kalkan 8 years ago
committed by GitHub
parent
commit
7e82d78549
  1. BIN
      src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll
  2. 9
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityRolesInput.cs
  3. 9
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs
  4. 8
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs
  5. 2
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs
  6. 11
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs
  7. 13
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs
  8. 1
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs
  9. 4
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs
  10. 13
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs
  11. 5
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  12. 5
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs
  13. 3
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  14. 14
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs
  15. 13
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs
  16. 63
      src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs
  17. 8
      src/Volo.Abp.Identity.Web/Areas/Identity/Models/CreateOrUpdateUserViewModel.cs
  18. 52
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml
  19. 64
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml
  20. 62
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml
  21. 11
      src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj
  22. 9
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css
  23. 158
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js
  24. 9
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less
  25. 2
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css
  26. 2
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs
  27. 2
      test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs

BIN
src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll

Binary file not shown.

9
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityRolesInput.cs

@ -0,0 +1,9 @@
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity
{
public class GetIdentityRolesInput : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
}
}

9
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs

@ -0,0 +1,9 @@
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity
{
public class GetIdentityUsersInput : PagedAndSortedResultRequestDto
{
public string Filter { get; set; }
}
}

8
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityRoleAppService.cs

@ -1,11 +1,13 @@
using System;
using Volo.Abp.Application.Dtos;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity
{
public interface IIdentityRoleAppService : IAsyncCrudAppService<IdentityRoleDto, Guid, PagedAndSortedResultRequestDto, IdentityRoleCreateDto, IdentityRoleUpdateDto>
public interface IIdentityRoleAppService : IAsyncCrudAppService<IdentityRoleDto, Guid, GetIdentityRolesInput, IdentityRoleCreateDto, IdentityRoleUpdateDto>
{
//TODO: remove after a better design
Task<List<IdentityRoleDto>> GetAllListAsync();
}
}

2
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs

@ -5,7 +5,7 @@ using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity
{
public interface IIdentityUserAppService : IAsyncCrudAppService<IdentityUserDto, Guid, PagedAndSortedResultRequestDto, IdentityUserCreateDto, IdentityUserUpdateDto>
public interface IIdentityUserAppService : IAsyncCrudAppService<IdentityUserDto, Guid, GetIdentityUsersInput, IdentityUserCreateDto, IdentityUserUpdateDto>
{
Task<ListResultDto<IdentityRoleDto>> GetRolesAsync(Guid id);

11
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs

@ -0,0 +1,11 @@
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity
{
public class IdentityUserCreateOrUpdateOutput
{
public IdentityUserDto User { get; set; }
public IdentityUserRoleDto[] Roles { get; set; }
}
}

13
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs

@ -0,0 +1,13 @@
using System;
namespace Volo.Abp.Identity
{
public class IdentityUserRoleDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public bool IsAssigned { get; set; }
}
}

1
src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs

@ -2,6 +2,5 @@
{
public class IdentityUserUpdateDto : IdentityUserCreateOrUpdateDtoBase
{
}
}

4
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs

@ -1,4 +1,5 @@
using AutoMapper;
using System.Collections.Generic;
using AutoMapper;
namespace Volo.Abp.Identity
{
@ -8,6 +9,7 @@ namespace Volo.Abp.Identity
{
CreateMap<IdentityUser, IdentityUserDto>();
CreateMap<IdentityRole, IdentityRoleDto>();
CreateMap<IdentityRoleDto, IdentityUserRoleDto>();
}
}
}

13
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityRoleAppService.cs

@ -12,7 +12,7 @@ namespace Volo.Abp.Identity
private readonly IIdentityRoleRepository _roleRepository;
public IdentityRoleAppService(
IdentityRoleManager roleManager,
IdentityRoleManager roleManager,
IIdentityRoleRepository roleRepository)
{
_roleManager = roleManager;
@ -26,10 +26,10 @@ namespace Volo.Abp.Identity
);
}
public async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(PagedAndSortedResultRequestDto input)
public async Task<PagedResultDto<IdentityRoleDto>> GetListAsync(GetIdentityRolesInput input)
{
var count = (int)await _roleRepository.GetCountAsync();
var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount);
var list = await _roleRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
return new PagedResultDto<IdentityRoleDto>(
count,
@ -37,6 +37,13 @@ namespace Volo.Abp.Identity
);
}
public async Task<List<IdentityRoleDto>> GetAllListAsync()
{
var list = await _roleRepository.GetAllListAsync();
return ObjectMapper.Map<List<IdentityRole>, List<IdentityRoleDto>>(list);
}
public async Task<IdentityRoleDto> CreateAsync(IdentityRoleCreateDto input)
{
var role = new IdentityRole(GuidGenerator.Create(), input.Name);

5
src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
@ -26,10 +27,10 @@ namespace Volo.Abp.Identity
);
}
public async Task<PagedResultDto<IdentityUserDto>> GetListAsync(PagedAndSortedResultRequestDto input)
public async Task<PagedResultDto<IdentityUserDto>> GetListAsync(GetIdentityUsersInput input)
{
var count = (int)await _userRepository.GetCountAsync();
var list = await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount);
var list = await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount, input.Filter);
return new PagedResultDto<IdentityUserDto>(
count,

5
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityRoleRepository.cs

@ -9,6 +9,9 @@ namespace Volo.Abp.Identity
{
Task<IdentityRole> FindByNormalizedNameAsync(string normalizedRoleName, CancellationToken cancellationToken);
Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount);
Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter);
//TODO: remove after a better design
Task<List<IdentityRole>> GetAllListAsync();
}
}

3
src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs

@ -24,7 +24,8 @@ namespace Volo.Abp.Identity
//TODO: Why not return List instead of IList
Task<IList<IdentityUser>> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken);
Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount);
//TODO: DTO can be used instead of parameters
Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter);
Task<List<IdentityRole>> GetRolesAsync(Guid userId);
}

14
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityRoleRepository.cs

@ -7,6 +7,7 @@ using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.Identity.EntityFrameworkCore;
using System;
namespace Volo.Abp.Identity
{
@ -22,9 +23,18 @@ namespace Volo.Abp.Identity
return DbSet.FirstOrDefaultAsync(r => r.NormalizedName == normalizedRoleName, cancellationToken);
}
public async Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount)
public async Task<List<IdentityRole>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
{
return await this.OrderBy(sorting ?? nameof(IdentityRole.Name)).PageBy(skipCount, maxResultCount).ToListAsync();
return await this.WhereIf(
!filter.IsNullOrWhiteSpace(),
r => r.Name.Contains(filter)
).OrderBy(sorting ?? nameof(IdentityRole.Name))
.PageBy(skipCount, maxResultCount).ToListAsync();
}
public async Task<List<IdentityRole>> GetAllListAsync()
{
return await GetQueryable().ToListAsync();
}
}
}

13
src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs

@ -78,6 +78,18 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(cancellationToken);
}
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter)
{
return await this.WhereIf(
!filter.IsNullOrWhiteSpace(),
u =>
u.UserName.Contains(filter) ||
u.Email.Contains(filter)
)
.OrderBy(sorting ?? nameof(IdentityUser.UserName))
.PageBy(skipCount, maxResultCount).ToListAsync();
}
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
return await this.OrderBy(sorting ?? nameof(IdentityUser.UserName)).PageBy(skipCount, maxResultCount).ToListAsync();
@ -87,6 +99,7 @@ namespace Volo.Abp.Identity
{
var query = from userRole in DbContext.UserRoles
join role in DbContext.Roles on userRole.RoleId equals role.Id
where userRole.UserId == userId
select role;
return await query.ToListAsync();

63
src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs

@ -1,8 +1,11 @@
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Identity.Web.Areas.Identity.Models;
namespace Volo.Abp.Identity.Web.Areas.Identity.Controllers
{
@ -10,17 +13,63 @@ namespace Volo.Abp.Identity.Web.Areas.Identity.Controllers
[Authorize]
public class UsersController : AbpController
{
private readonly IIdentityUserAppService _userAppService;
private readonly IIdentityUserAppService _identityUserAppService;
private readonly IIdentityRoleAppService _identityRoleAppService;
public UsersController(IIdentityUserAppService userAppService)
public UsersController(IIdentityUserAppService identityUserAppService, IIdentityRoleAppService identityRoleAppService)
{
_userAppService = userAppService;
_identityUserAppService = identityUserAppService;
_identityRoleAppService = identityRoleAppService;
}
public async Task<ActionResult> Index()
{
var result = await _userAppService.GetListAsync(new PagedAndSortedResultRequestDto());
return View(result.Items);
return View();
}
public async Task<PartialViewResult> Create()
{
var model = await CreateViewModel(null);
return PartialView("_Create", model);
}
public async Task<PartialViewResult> Update(Guid id)
{
var user = await _identityUserAppService.GetAsync(id);
await _identityRoleAppService.GetAllListAsync();
var model = await CreateViewModel(user);
return PartialView("_Update", model);
}
private async Task<CreateOrUpdateUserViewModel> CreateViewModel(IdentityUserDto user)
{
var allRoles = await _identityRoleAppService.GetAllListAsync();
var model = new CreateOrUpdateUserViewModel
{
User = user ?? new IdentityUserDto(),
Roles = ObjectMapper.Map<List<IdentityRoleDto>, IdentityUserRoleDto[]>(allRoles)
};
var userRoles = new List<IdentityRoleDto>();
if (user != null)
{
userRoles = (await _identityUserAppService.GetRolesAsync(user.Id)).Items.ToList();
}
foreach (var role in model.Roles)
{
if (userRoles.Select(x=>x.Name).Contains(role.Name))
{
role.IsAssigned = true;
}
}
return model;
}
}
}

8
src/Volo.Abp.Identity.Web/Areas/Identity/Models/CreateOrUpdateUserViewModel.cs

@ -0,0 +1,8 @@
namespace Volo.Abp.Identity.Web.Areas.Identity.Models
{
public class CreateOrUpdateUserViewModel
{
public IdentityUserDto User { get; set; }
public IdentityUserRoleDto[] Roles { get; set; }
}
}

52
src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml

@ -1,34 +1,42 @@
@model IReadOnlyList<Volo.Abp.Identity.IdentityUserDto>
@section styles {
@section styles {
<!-- TODO: Use minified on production, normal in development -->
<link rel="stylesheet" type="text/css" href="~/modules/identity/libs/datatables/datatables.min.css" />
<link rel="stylesheet" type="text/css" href="~/modules/identity/views/users/index.css" />
}
@section scripts {
<script type="text/javascript" src="~/modules/identity/libs/datatables/datatables.min.js"></script>
<script type="text/javascript" src="~/modules/identity/libs/datatables/datatables.js"></script>
<script type="text/javascript" src="~/modules/identity/views/users/index.js"></script>
}
<h2>Users</h2>
<div class="row">
<div class="col-md-6">
<h2>Users</h2>
</div>
<div class="col-md-6 text-right">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary create-user" data-toggle="modal">
Create User
</button>
</div>
</div>
<table id="IdentityUsersTable">
<table id="IdentityUsersTable" class="table table-striped table-bordered table-hover nowrap">
<thead>
<tr>
<th>Username</th>
<th>Email Address</th>
<th>Phone Number</th>
</tr>
<tr>
<th>Actions</th>
<th>Username</th>
<th>Email Address</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody>
@foreach (var user in Model)
{
<tr>
<td>@user.UserName</td>
<td>@user.Email</td>
<td>@(user.PhoneNumber ?? "-")</td>
</tr>
}
</tbody>
</table>
</table>
<!-- Modal -->
<div class="modal fade" id="createUpdateUserModal" tabindex="-1" role="dialog" aria-labelledby="userModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
</div>
</div>
</div>

64
src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml

@ -0,0 +1,64 @@
@model Volo.Abp.Identity.Web.Areas.Identity.Controllers.CreateOrUpdateUserViewModel
<div class="modal-header">
<h5 class="modal-title" id="userModalLabel">Create User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="createUserForm">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#userInformations" role="tab">User informations</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#roles" role="tab">Roles</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content pt-3">
<div class="tab-pane active" id="userInformations" role="tabpanel">
<div class="form-group">
<label for="userName">User name</label>
<input type="text" class="form-control" id="userName" name="UserName" placeholder="User name">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="Password" placeholder="Password">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="Email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="phoneNumber">Phone number</label>
<input type="tel" class="form-control" id="phoneNumber" name="PhoneNumber" placeholder="Phone number">
</div>
</div>
<div class="tab-pane" id="roles" role="tabpanel">
<div class="user-role-checkbox-list">
@foreach (var role in Model.Roles)
{
<div class="form-check">
<label class="form-check-label">
<input id="CreateUser_@(role.Name)" class="form-check-input" type="checkbox" name="@(role.Name)" value="true" @Html.Raw(role.IsAssigned ? "checked=\"checked\"" : "")>
@role.Name
</label>
</div>
}
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="btnCreateUserSave">Save</button>
</div>

62
src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml

@ -0,0 +1,62 @@
@model Volo.Abp.Identity.Web.Areas.Identity.Controllers.CreateOrUpdateUserViewModel
<div class="modal-header">
<h5 class="modal-title" id="userModalLabel">Update User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="updateUserForm">
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-toggle="tab" href="#userInformations" role="tab">User informations</a>
</li>
<li class="nav-item">
<a class="nav-link" data-toggle="tab" href="#roles" role="tab">Roles</a>
</li>
</ul>
<!-- Tab panes -->
<div class="tab-content pt-3">
<div class="tab-pane active" id="userInformations" role="tabpanel">
<input type="hidden" name="Id" value="@Model.User.Id" />
<div class="form-group">
<label for="userName">User name</label>
<input type="text" class="form-control" id="userName" name="UserName" placeholder="User name" value="@Model.User.UserName">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="Email" placeholder="Enter email" value="@Model.User.Email">
</div>
<div class="form-group">
<label for="phoneNumber">Phone number</label>
<input type="tel" class="form-control" id="phoneNumber" name="PhoneNumber" placeholder="Phone number" value="@Model.User.PhoneNumber">
</div>
</div>
<div class="tab-pane" id="roles" role="tabpanel">
<div class="user-role-checkbox-list">
@foreach (var role in Model.Roles)
{
<div class="form-check">
<label class="form-check-label">
<input id="CreateUser_@(role.Name)" class="form-check-input" type="checkbox" name="@(role.Name)" value="true" @Html.Raw(role.IsAssigned ? "checked=\"checked\"" : "")>
@role.Name
</label>
</div>
}
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="btnUpdateUserSave">Save</button>
</div>

11
src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj

@ -11,7 +11,16 @@
<ItemGroup>
<EmbeddedResource Include="Areas\**\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<EmbeddedResource Include="wwwroot\**\*.*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
<EmbeddedResource Include="wwwroot\modules\identity\libs\datatables\datatables.css" />
<EmbeddedResource Include="wwwroot\modules\identity\libs\datatables\datatables.js" />
<EmbeddedResource Include="wwwroot\modules\identity\libs\datatables\datatables.min.css" />
<EmbeddedResource Include="wwwroot\modules\identity\libs\datatables\datatables.min.js" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.css" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.es5.js" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.es5.min.js" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.js" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.less" />
<EmbeddedResource Include="wwwroot\modules\identity\views\users\index.min.css" />
</ItemGroup>
<ItemGroup>

9
src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css

@ -1,3 +1,8 @@
#IdentityUsersTable {
width: 100%;
.dataTable {
width: 100% !important;
border-spacing: 0 !important;
}
.table td,
.table th {
padding: 8px 10px;
}

158
src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js

@ -1,3 +1,155 @@
$(function() {
$('#IdentityUsersTable').DataTable();
});
$(function () {
var _identityUserAppService = volo.abp.identity.identityUser;
var dataTable = $('#IdentityUsersTable').DataTable({
paging: true,
serverSide: true,
processing: true,
responsive: true,
order: [[1, "asc"]],
ajax: function (requestData, callback, settings) {
var inputFilter = {};
//set paging filters
if (settings.oInit.paging) {
inputFilter = $.extend(inputFilter, {
maxResultCount: requestData.length,
skipCount: requestData.start
});
}
//set sorting filter
if (requestData.order && requestData.order.length > 0) {
var orderingField = requestData.order[0];
if (requestData.columns[orderingField.column].data) {
inputFilter.sorting = requestData.columns[orderingField.column].data + " " + orderingField.dir;
}
}
//set searching filter
if (requestData.search && requestData.search.value !== "") {
inputFilter.filter = requestData.search.value;
}
if (callback) {
_identityUserAppService.getList(inputFilter).done(function (result) {
callback({
recordsTotal: result.totalCount,
recordsFiltered: result.totalCount,
data: result.items
});
});
}
},
columnDefs: [
{
targets: 0,
data: null,
orderable: false,
autoWidth: false,
defaultContent: '',
render: function (list, type, record, meta) {
return '<div class="dropdown">' +
'<button class="btn btn-primary btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
'Actions' +
'</button>' +
'<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">' +
'<a class="dropdown-item update-user" href="#" data-id="' + record.id + '">Edit</a>' +
'<a class="dropdown-item delete-user" href="#" data-id="' + record.id + '">Delete</a>' +
'</div>' +
'</div>';
}
},
{
targets: 1,
data: "userName"
},
{
targets: 2,
data: "email"
},
{
targets: 3,
data: "phoneNumber"
}
]
});
$('#IdentityUsersTable').on('click', '.update-user', function () {
var id = $(this).data('id');
$('#createUpdateUserModal').modal('show')
.find('.modal-content')
.load(abp.appPath + 'Identity/Users/Update', { id: id });
});
$('#IdentityUsersTable').on('click', '.delete-user', function () {
var id = $(this).data('id');
if (confirm('Are you sure you want to delete?')) {
_identityUserAppService.delete(id).done(function () {
dataTable.ajax.reload();
});
}
});
$('.create-user').click(function () {
$('#createUpdateUserModal').modal('show')
.find('.modal-content')
.load(abp.appPath + 'Identity/Users/Create');
});
$('#createUpdateUserModal').on('click', '#btnCreateUserSave', function () {
var $createUserForm = $('#createUserForm');
var user = $createUserForm.serializeFormToObject();
user.RoleNames = findAssignedRoleNames();
_identityUserAppService.create(user).done(function () {
$('#createUpdateUserModal').modal('hide');
dataTable.ajax.reload();
});
});
$('#createUpdateUserModal').on('click', '#btnUpdateUserSave', function () {
var $updateUserForm = $('#updateUserForm');
var user = $updateUserForm.serializeFormToObject();
user.RoleNames = findAssignedRoleNames();
_identityUserAppService.update(user.Id, user).done(function () {
$('#createUpdateUserModal').modal('hide');
dataTable.ajax.reload();
});
});
});
function findAssignedRoleNames() {
var assignedRoleNames = [];
$(document).find('.user-role-checkbox-list input[type=checkbox]')
.each(function () {
if ($(this).is(':checked')) {
assignedRoleNames.push($(this).attr('name'));
}
});
return assignedRoleNames;
}
//TODO: move to common script file
$.fn.serializeFormToObject = function () {
//serialize to array
var data = $(this).serializeArray();
//add also disabled items
$(':disabled[name]', this)
.each(function () {
data.push({ name: this.name, value: $(this).val() });
});
//map to object
var obj = {};
data.map(function (x) { obj[x.name] = x.value; });
return obj;
};

9
src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less

@ -1,3 +1,8 @@
#IdentityUsersTable {
width: 100%;
.dataTable {
width: 100% !important;
border-spacing: 0 !important;
}
.table td, .table th {
padding: 8px 10px;
}

2
src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css

@ -1 +1 @@
#IdentityUsersTable{width:100%;}
.dataTable{width:100% !important;border-spacing:0 !important;}.table td,.table th{padding:8px 10px;}

2
test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityRoleAppService_Tests.cs

@ -40,7 +40,7 @@ namespace Volo.Abp.Identity
{
//Act
var result = await _roleAppService.GetListAsync(new PagedAndSortedResultRequestDto());
var result = await _roleAppService.GetListAsync(new GetIdentityRolesInput());
//Assert

2
test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs

@ -44,7 +44,7 @@ namespace Volo.Abp.Identity
{
//Act
var result = await _userAppService.GetListAsync(new PagedAndSortedResultRequestDto());
var result = await _userAppService.GetListAsync(new GetIdentityUsersInput());
//Assert

Loading…
Cancel
Save