From 44ff921a6a7a2f7c9f0a498f977b29a12d235cc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?alir=C4=B1za=20ad=C4=B1yah=C5=9Fi?= Date: Wed, 11 Oct 2017 10:58:29 +0300 Subject: [PATCH] user crud operations --- src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll | Bin 15872 -> 15360 bytes .../Abp/Identity/GetIdentityUsersInput.cs | 10 ++ .../Abp/Identity/IIdentityUserAppService.cs | 2 +- .../IdentityUserCreateOrUpdateOutput.cs | 11 ++ .../Volo/Abp/Identity/IdentityUserRoleDto.cs | 13 ++ .../Abp/Identity/IdentityUserUpdateDto.cs | 1 - ...pDeskApplicationModuleAutoMapperProfile.cs | 1 + .../Abp/Identity/IdentityUserAppService.cs | 29 +++- .../Abp/Identity/IIdentityUserRepository.cs | 3 +- .../Identity/EfCoreIdentityUserRepository.cs | 12 ++ .../Identity/Controllers/UsersController.cs | 25 +++- .../Areas/Identity/Views/Users/Index.cshtml | 43 +++--- .../Areas/Identity/Views/Users/_Create.cshtml | 63 ++++++++ .../Areas/Identity/Views/Users/_Update.cshtml | 30 ++++ .../Volo.Abp.Identity.Web.csproj | 11 +- .../modules/identity/views/users/index.css | 5 +- .../modules/identity/views/users/index.js | 141 +++++++++++++++++- .../modules/identity/views/users/index.less | 5 +- .../identity/views/users/index.min.css | 2 +- .../Services/IAsyncCrudAppService.cs | 2 + .../Identity/IdentityUserAppService_Tests.cs | 2 +- 21 files changed, 368 insertions(+), 43 deletions(-) create mode 100644 src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs create mode 100644 src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs create mode 100644 src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs create mode 100644 src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml create mode 100644 src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml diff --git a/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll b/src/AbpDesk/Web_PlugIns/AbpDesk.MongoBlog.dll index 243e6fa82e786a375d8e95b05012435cd1ccff0c..b7cc055fbd1dab34af45b3dcaa3e4568c123b15d 100644 GIT binary patch delta 5005 zcmZu#3vg7`8UD|?cke5^m)*PB&6Btx*|6C>8XzDKc|=Gdg~%I*HYyasNd;E2&=Di- zW>7%|Yq)9$tr~n(u~w@AgsE1dh*L%d#An46P;7mn9l$5je&_6_g5w?bJOBIq=bZmP z_lER!>1%FVKVZ({WlvD{IYI*>IjoMT9s(^Rd~-(UqjT(z8AMZsU_Q}KrL#2XO%r*+ zzdoI4xZ5zS+MUM+T89Ti6v40Fy_r?9VeSq#kd1VE*?@}eh#;Ox_;K>kwkXjTWkgI$ zi5_essxuHNo*Kzxc|;ahRzs=ADOks81kAt%9OA2ekUA90hs|o_06Mff2cy<5xEzN; z3EL`%t`mY-Aq?a257sHvkeyChTPq0t~O&9xD6L$$+1e|g|n!Ni74;w$8=doEV(MEngKO|9IUo~z_HC{ zbam2!NjOmjVTIJX&no39&)E>tEed#&B_cvKw9y2XuC-0zaJ&SN>->aKHjv(SH7tHe z#7NX2g5K79p0qdDsMd@`EmViKYE8>facZbf$=#umNdFXmwb(7JQ9jr;SxVKA4L?U- z!ec*!Rs3-!fs(Y^PGKq@8w4_jGP4pxgiuwmV3ezs7z&6NuE80pakvf>?5%kl;mV@n z1AZ)?$1W5ue&I6QwLPQz!48FG#m{C&cZsKH?kEVjnn2}f+>@}ykh}=81gb)d&rsUR z;U9y#s)8%hEWW92BxF1`TDT@~E*ejuNVN+hu`v+E#sb_^p2igB8wWbRDKo-9EQ~z~ z)Ut+2i^X882~?~stYDpoHeq|Ps6f%i@p36`EB-&1EROr5d2MMSN`&B*73H_xB}M3? zK2bs2j#4Q@k@v|8+uoF-0*EYhO@n(>3#U+b7P=^g`K(O5*aVTaD0GFkBOi1?fVYdD zv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fW4rO?;D`{d|N!Zf7C+p|JsYAUMc= z%^$LELT1Psi7jkSvh6gfw+J zbx_VZ{x-L1}}TWFWMfCgzoT}7kxt~x{>Bt!HE+O4jqrz!iI zZ$yelq-adiW0Kw{>HP&14sS}DF%g0>AyFhVwcW(QoKc_BQ*1#kdb!N)vD0RIQ9)YyHy}_^aR+ z;LoIFtu7>cjYolh;3GKR{qhf3fV_BkY1e$hw;3(O#yf+$(XuXf4eMiD*{kezwuoQM z)tuP1$N%QzgO494@c5mQJzlnn|Hm5(N3u5*T#t`1B3{n$J6;x-%!v`!;S1x$Oq+P; z*U0|%HL}O^GW>-*_S?iQyi(?WBHIi2INgVgg5HWp5}!?iJ{JezW_kSKZ5s4h&aD8!if9F7Nw>Lbw%zG!+5LwuL#r3OKcW35j(%-`(4JbtZlN>Z?beFZoX}6uNus1@|p$ZQWKkZR6at zZl3MEQd2YMS}noYWT#!+!nx-yojdVpcqMZ#)$%v2j36SUH!{XT75GqLPTats7pKcR zskSsb?Bs@{PVU#t$vq)-A)~-O911ZGguMvuM+6>qhJuJADv$ycEd@S&Qrgltw*{HQxjhy%lekk1Qcv&*jwO!P zh{|;2-;MmGJ~S^vrs&D_NLs0)R) zG($^p5H_BWS5O7ncph8SH47`VN0WY~iq32$LAI>Z&`Hgr+<4s5l|r|KmZN|OUd5O_ z*^cNw!?`pXUW0TPlSs@5ytBG!Jc zIHJV2XnzN;Q@syPsVcu>SNG2I8o#l0TWCXV?zwj_6s`+fRxIx6zuHSR)%oPE^)6|u xwTlY>M}z^@b$YiqmGSaU@4=?J(N~*hGVi0NO`~@6X9}O)G#YOCkPSEL{{t~Kg53ZB diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/GetIdentityUsersInput.cs new file mode 100644 index 0000000000..274800728a --- /dev/null +++ b/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; } + } +} diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs index 8738265374..c620ebd917 100644 --- a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IIdentityUserAppService.cs +++ b/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 + public interface IIdentityUserAppService : IAsyncCrudAppService { Task> GetRolesAsync(Guid id); diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserCreateOrUpdateOutput.cs new file mode 100644 index 0000000000..e107db6b71 --- /dev/null +++ b/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; } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserRoleDto.cs new file mode 100644 index 0000000000..eea833d957 --- /dev/null +++ b/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; } + } +} diff --git a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs index cc551a7398..3117ff8003 100644 --- a/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs +++ b/src/Volo.Abp.Identity.Application.Contracts/Volo/Abp/Identity/IdentityUserUpdateDto.cs @@ -2,6 +2,5 @@ { public class IdentityUserUpdateDto : IdentityUserCreateOrUpdateDtoBase { - } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs index e796a0a7ae..6f922c9707 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs +++ b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/AbpDeskApplicationModuleAutoMapperProfile.cs @@ -8,6 +8,7 @@ namespace Volo.Abp.Identity { CreateMap(); CreateMap(); + CreateMap(); } } } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs b/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs index fc264b4a60..68b92a04c5 100644 --- a/src/Volo.Abp.Identity.Application/Volo/Abp/Identity/IdentityUserAppService.cs +++ b/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 GetAsync(Guid id) @@ -26,10 +29,30 @@ namespace Volo.Abp.Identity ); } - public async Task> GetListAsync(PagedAndSortedResultRequestDto input) + public async Task GetUserForCreateOrUpdateAsync(Guid id) + { + var userRoleDtos = ObjectMapper.Map, IdentityUserRoleDto[]>(await _roleRepository.GetListAsync()); + var output = new IdentityUserCreateOrUpdateOutput + { + Roles = userRoleDtos + }; + + var user = await _userManager.GetByIdAsync(id); + + output.User = ObjectMapper.Map(user); + + foreach (var userRoleDto in userRoleDtos) + { + userRoleDto.IsAssigned = await _userManager.IsInRoleAsync(user, userRoleDto.Name); + } + + return output; + } + + public async Task> 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( count, diff --git a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs b/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs index d583b83f46..39b1b649bb 100644 --- a/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIdentityUserRepository.cs +++ b/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> GetListByNormalizedRoleNameAsync(string normalizedRoleName, CancellationToken cancellationToken); - Task> GetListAsync(string sorting, int maxResultCount, int skipCount); + //TODO: DTO can be used instead of parameters + Task> GetListAsync(string sorting, int maxResultCount, int skipCount, string filter); Task> GetRolesAsync(Guid userId); } diff --git a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs b/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs index a845d8faf8..65ab54b5a6 100644 --- a/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EfCoreIdentityUserRepository.cs +++ b/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> 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> GetListAsync(string sorting, int maxResultCount, int skipCount) { return await this.OrderBy(sorting ?? nameof(IdentityUser.UserName)).PageBy(skipCount, maxResultCount).ToListAsync(); diff --git a/src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs b/src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs index 9450115d66..300395bf19 100644 --- a/src/Volo.Abp.Identity.Web/Areas/Identity/Controllers/UsersController.cs +++ b/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 Index() { - var result = await _userAppService.GetListAsync(new PagedAndSortedResultRequestDto()); - return View(result.Items); + return View(); + } + + public async Task _Create() + { + return PartialView(); + } + + public async Task _Update(Guid id) + { + var identityUser = await _identityUserAppService.GetUserForCreateOrUpdateAsync(id); + + return PartialView(identityUser); } } } diff --git a/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml index ed16546d72..7e498ddaa8 100644 --- a/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml +++ b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/Index.cshtml @@ -1,34 +1,37 @@ -@model IReadOnlyList - -@section styles { +@section styles { } @section scripts { - + }

Users

- + + + + + + +
- - - - - + + + + + + - - @foreach (var user in Model) - { - - - - - - } -
UsernameEmail AddressPhone Number
ActionsUsernameEmail AddressPhone Number
@user.UserName@user.Email@(user.PhoneNumber ?? "-")
\ No newline at end of file diff --git a/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml new file mode 100644 index 0000000000..623fae0570 --- /dev/null +++ b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Create.cshtml @@ -0,0 +1,63 @@ +@model Volo.Abp.Identity.IdentityUserDto + + + + \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml new file mode 100644 index 0000000000..0f1b7fedc2 --- /dev/null +++ b/src/Volo.Abp.Identity.Web/Areas/Identity/Views/Users/_Update.cshtml @@ -0,0 +1,30 @@ +@model Volo.Abp.Identity.IdentityUserDto + + + + \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj b/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj index 4cb0a66f59..efe55cc4a5 100644 --- a/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj +++ b/src/Volo.Abp.Identity.Web/Volo.Abp.Identity.Web.csproj @@ -11,7 +11,16 @@ - + + + + + + + + + + diff --git a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css index 00bc312198..ee22283b8e 100644 --- a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.css +++ b/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; } \ No newline at end of file diff --git a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js index 7170f72224..393c59095c 100644 --- a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js +++ b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.js @@ -1,3 +1,138 @@ -$(function() { - $('#IdentityUsersTable').DataTable(); -}); \ No newline at end of file +$(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 ''; + } + }, + { + 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; +}; diff --git a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less index f267dfefb8..b566f7d35c 100644 --- a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.less +++ b/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; } diff --git a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css index 3690048700..557de2f607 100644 --- a/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css +++ b/src/Volo.Abp.Identity.Web/wwwroot/modules/identity/views/users/index.min.css @@ -1 +1 @@ -#IdentityUsersTable{width:100%;} \ No newline at end of file +.dataTable{width:100% !important;border-spacing:0 !important;} \ No newline at end of file diff --git a/src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs b/src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs index a94d0ce554..50f9314875 100644 --- a/src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs +++ b/src/Volo.Abp/Volo/Abp/Application/Services/IAsyncCrudAppService.cs @@ -38,6 +38,8 @@ namespace Volo.Abp.Application.Services { Task GetAsync(TPrimaryKey id); + Task GetUserForCreateOrUpdateAsync(Guid id); + Task> GetListAsync(TGetListInput input); Task CreateAsync(TCreateInput input); diff --git a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs b/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs index a4bbb9af11..4025713ae1 100644 --- a/test/Volo.Abp.Identity.Application.Tests/Volo/Abp/Identity/IdentityUserAppService_Tests.cs +++ b/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