Browse Source

user crud operations

pull/129/head
alirıza adıyahşi 9 years ago
parent
commit
44ff921a6a
  1. BIN
      src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll
  2. 10
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs
  3. 2
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs
  4. 11
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs
  5. 13
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs
  6. 1
      src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs
  7. 1
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs
  8. 29
      src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs
  9. 3
      src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs
  10. 12
      src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs
  11. 25
      src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs
  12. 43
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml
  13. 63
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml
  14. 30
      src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml
  15. 11
      src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj
  16. 5
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css
  17. 141
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js
  18. 5
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less
  19. 2
      src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css
  20. 2
      src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs
  21. 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.

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

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

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: EntityDto
{
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
{
}
}

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

@ -8,6 +8,7 @@ namespace Volo.Abp.Identity
{
CreateMap<IdentityUser, IdentityUserDto>();
CreateMap<IdentityRole, IdentityRoleDto>();
CreateMap<IdentityRole, IdentityUserRoleDto>();
}
}
}

29
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;
@ -12,11 +13,13 @@ namespace Volo.Abp.Identity
{
private readonly IdentityUserManager _userManager;
private readonly IIdentityUserRepository _userRepository;
private readonly IIdentityRoleRepository _roleRepository;
public IdentityUserAppService(IdentityUserManager userManager, IIdentityUserRepository userRepository)
public IdentityUserAppService(IdentityUserManager userManager, IIdentityUserRepository userRepository, IIdentityRoleRepository roleRepository)
{
_userManager = userManager;
_userRepository = userRepository;
_roleRepository = roleRepository;
}
public async Task<IdentityUserDto> GetAsync(Guid id)
@ -26,10 +29,30 @@ namespace Volo.Abp.Identity
);
}
public async Task<PagedResultDto<IdentityUserDto>> GetListAsync(PagedAndSortedResultRequestDto input)
public async Task<IdentityUserCreateOrUpdateOutput> GetUserForCreateOrUpdateAsync(Guid id)
{
var userRoleDtos = ObjectMapper.Map<List<IdentityRole>, IdentityUserRoleDto[]>(await _roleRepository.GetListAsync());
var output = new IdentityUserCreateOrUpdateOutput
{
Roles = userRoleDtos
};
var user = await _userManager.GetByIdAsync(id);
output.User = ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
foreach (var userRoleDto in userRoleDtos)
{
userRoleDto.IsAssigned = await _userManager.IsInRoleAsync(user, userRoleDto.Name);
}
return output;
}
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,

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);
}

12
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();

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

@ -1,6 +1,6 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Dtos;
using Volo.Abp.AspNetCore.Mvc;
namespace Volo.Abp.Identity.Web.Areas.Identity.Controllers
@ -8,17 +8,28 @@ namespace Volo.Abp.Identity.Web.Areas.Identity.Controllers
[Area("Identity")]
public class UsersController : AbpController
{
private readonly IIdentityUserAppService _userAppService;
private readonly IIdentityUserAppService _identityUserAppService;
public UsersController(IIdentityUserAppService userAppService)
public UsersController(IIdentityUserAppService identityUserAppService)
{
_userAppService = userAppService;
_identityUserAppService = identityUserAppService;
}
public async Task<ActionResult> Index()
{
var result = await _userAppService.GetListAsync(new PagedAndSortedResultRequestDto());
return View(result.Items);
return View();
}
public async Task<ActionResult> _Create()
{
return PartialView();
}
public async Task<ActionResult> _Update(Guid id)
{
var identityUser = await _identityUserAppService.GetUserForCreateOrUpdateAsync(id);
return PartialView(identityUser);
}
}
}

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

@ -1,34 +1,37 @@
@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>
<table id="IdentityUsersTable">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary create-user" data-toggle="modal">
Create User
</button>
<!-- 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>
<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>

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

@ -0,0 +1,63 @@
@model Volo.Abp.Identity.IdentityUserDto
<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">
<!-- 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">
<div class="tab-pane active" id="userInformations" role="tabpanel">
<form id="createUserForm">
<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>
</form>
</div>
<div class="tab-pane" id="roles" role="tabpanel">
@foreach (var role in Model.Roles)
{
<div class="form-check">
<label class="form-check-label">
<input id="EditUser_@(role.RoleName)" class="form-check-input" type="checkbox" name="@(role.RoleName)" value="true" @Html.Raw(role.IsAssigned ? "checked=\"checked\"" : "")>
<input class="form-check-input" type="checkbox" value="">
@role.RoleName
</label>
</div>
}
</div>
</div>
</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>

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

@ -0,0 +1,30 @@
@model Volo.Abp.Identity.IdentityUserDto
<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">
<input type="hidden" name="Id" value="@Model.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.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.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.PhoneNumber">
</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>

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

@ -1,3 +1,4 @@
#IdentityUsersTable {
width: 100%;
.dataTable {
width: 100% !important;
border-spacing: 0 !important;
}

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

@ -1,3 +1,138 @@
$(function() {
$('#IdentityUsersTable').DataTable();
});
$(function () {
var identityUserAppService = volo.abp.identity.identityUser;
var dataTable = $('#IdentityUsersTable').DataTable({
processing: true,
serverSide: true,
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
});
});
}
},
responsive: true,
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 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"
}
]
});
$(document).on('click', '.update-user', function () {
var id = $(this).data('id');
$('#createUpdateUserModal').modal('show')
.find('.modal-content')
.load(abp.appPath + 'Identity/Users/_Update', { id: id });
});
$(document).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');
});
$(document).on('click', '#btnCreateUserSave', function () {
var $createUserForm = $('#createUserForm');
var user = $createUserForm.serializeFormToObject();
identityUserAppService.create(user).done(function () {
$('#createUpdateUserModal').modal('hide');
dataTable.ajax.reload();
});
});
$(document).on('click', '#btnUpdateUserSave', function () {
var $updateUserForm = $('#updateUserForm');
var user = $updateUserForm.serializeFormToObject();
identityUserAppService.update(user.Id, user).done(function () {
$('#createUpdateUserModal').modal('hide');
dataTable.ajax.reload();
});
});
});
$.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;
};

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

@ -1,3 +1,4 @@
#IdentityUsersTable {
width: 100%;
.dataTable {
width: 100% !important;
border-spacing: 0 !important;
}

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;}

2
src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs

@ -38,6 +38,8 @@ namespace Volo.Abp.Application.Services
{
Task<TEntityDto> GetAsync(TPrimaryKey id);
Task<TEntityDto> GetUserForCreateOrUpdateAsync(Guid id);
Task<PagedResultDto<TEntityDto>> GetListAsync(TGetListInput input);
Task<TEntityDto> CreateAsync(TCreateInput input);

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