From 8dc6c37c5f8a37f0eab43fe4387a503c00874a5a Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Fri, 28 Sep 2018 09:57:14 +0300 Subject: [PATCH] IIdentityClaimTypeRepository improvements --- .../Identity/IIDentityClaimTypeRepository.cs | 4 ++++ .../Abp/Identity/IdenityClaimTypeManager.cs | 22 ++++++++----------- .../EfCoreIdentityClaimTypeRepository.cs | 17 ++++++++++++-- .../MongoIdentityClaimTypeRepository.cs | 16 +++++++++++++- 4 files changed, 43 insertions(+), 16 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs index bfc62de497..e55bdd966b 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs @@ -9,5 +9,9 @@ namespace Volo.Abp.Identity public interface IIdentityClaimTypeRepository : IBasicRepository { Task DoesNameExist(string name, Guid? claimTypeId = null); + + Task> GetListAsync(string sorting, int maxResultCount, int skipCount); + + Task GetTotalCount(); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs index a75bb566a7..eac38b9f24 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs @@ -7,7 +7,7 @@ using Volo.Abp.Guids; namespace Volo.Abp.Identity { - public class IdenityClaimTypeManager : IDomainService + public class IdenityClaimTypeManager : DomainService { private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; private readonly IGuidGenerator _guidGenerator; @@ -18,12 +18,7 @@ namespace Volo.Abp.Identity _guidGenerator = guidGenerator; } - public async Task GetAsync(Guid id) - { - return await _identityClaimTypeRepository.GetAsync(id); - } - - public async Task CreateAsync(IdentityClaimType claimType) + public virtual async Task CreateAsync(IdentityClaimType claimType) { if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name)) { @@ -33,19 +28,20 @@ namespace Volo.Abp.Identity return await _identityClaimTypeRepository.InsertAsync(claimType); } - public async Task UpdateAsync(IdentityClaimType claimType) + public virtual async Task UpdateAsync(IdentityClaimType claimType) { if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name, claimType.Id)) { throw new AbpException($"Name Exist: {claimType.Name}"); } - return await _identityClaimTypeRepository.UpdateAsync(claimType); - } + if (claimType.IsStatic) + { + throw new AbpException($"Can not update a static ClaimType."); + } + - public async Task DeleteAsync(Guid id) - { - await _identityClaimTypeRepository.DeleteAsync(id); + return await _identityClaimTypeRepository.UpdateAsync(claimType); } } } diff --git a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs index 81cab3ee8c..772ec91220 100644 --- a/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs @@ -1,10 +1,9 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Internal; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; @@ -20,5 +19,19 @@ namespace Volo.Abp.Identity.EntityFrameworkCore { return await DbSet.WhereIf(claimTypeId != null, ct => ct.Id == claimTypeId).CountAsync(ct => ct.Name == name) > 0; } + + public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) + { + var identityClaimTypes = await DbSet.OrderBy(sorting ?? "name desc") + .PageBy(skipCount, maxResultCount) + .ToListAsync(); + + return identityClaimTypes; + } + + public async Task GetTotalCount() + { + return await DbSet.CountAsync(); + } } } diff --git a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs index 3d80cc6520..fbc51bd773 100644 --- a/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs +++ b/modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; +using System.Linq.Dynamic.Core; using System.Threading.Tasks; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; @@ -19,5 +19,19 @@ namespace Volo.Abp.Identity.MongoDB { return GetMongoQueryable().WhereIf(claimTypeId != null, ct => ct.Id == claimTypeId).Count(ct => ct.Name == name) > 0; } + + public async Task> GetListAsync(string sorting, int maxResultCount, int skipCount) + { + var identityClaimTypes = GetMongoQueryable().OrderBy(sorting ?? "name desc") + .PageBy(skipCount, maxResultCount) + .ToList(); + + return identityClaimTypes; + } + + public async Task GetTotalCount() + { + return await GetMongoQueryable().CountAsync(); + } } }