Browse Source

IIdentityClaimTypeRepository improvements

pull/462/head
Yunus Emre Kalkan 8 years ago
parent
commit
8dc6c37c5f
  1. 4
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs
  2. 22
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs
  3. 17
      modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs
  4. 16
      modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs

4
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IIDentityClaimTypeRepository.cs

@ -9,5 +9,9 @@ namespace Volo.Abp.Identity
public interface IIdentityClaimTypeRepository : IBasicRepository<IdentityClaimType, Guid> public interface IIdentityClaimTypeRepository : IBasicRepository<IdentityClaimType, Guid>
{ {
Task<bool> DoesNameExist(string name, Guid? claimTypeId = null); Task<bool> DoesNameExist(string name, Guid? claimTypeId = null);
Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount);
Task<int> GetTotalCount();
} }
} }

22
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdenityClaimTypeManager.cs

@ -7,7 +7,7 @@ using Volo.Abp.Guids;
namespace Volo.Abp.Identity namespace Volo.Abp.Identity
{ {
public class IdenityClaimTypeManager : IDomainService public class IdenityClaimTypeManager : DomainService
{ {
private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository; private readonly IIdentityClaimTypeRepository _identityClaimTypeRepository;
private readonly IGuidGenerator _guidGenerator; private readonly IGuidGenerator _guidGenerator;
@ -18,12 +18,7 @@ namespace Volo.Abp.Identity
_guidGenerator = guidGenerator; _guidGenerator = guidGenerator;
} }
public async Task<IdentityClaimType> GetAsync(Guid id) public virtual async Task<IdentityClaimType> CreateAsync(IdentityClaimType claimType)
{
return await _identityClaimTypeRepository.GetAsync(id);
}
public async Task<IdentityClaimType> CreateAsync(IdentityClaimType claimType)
{ {
if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name)) if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name))
{ {
@ -33,19 +28,20 @@ namespace Volo.Abp.Identity
return await _identityClaimTypeRepository.InsertAsync(claimType); return await _identityClaimTypeRepository.InsertAsync(claimType);
} }
public async Task<IdentityClaimType> UpdateAsync(IdentityClaimType claimType) public virtual async Task<IdentityClaimType> UpdateAsync(IdentityClaimType claimType)
{ {
if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name, claimType.Id)) if (await _identityClaimTypeRepository.DoesNameExist(claimType.Name, claimType.Id))
{ {
throw new AbpException($"Name Exist: {claimType.Name}"); 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) return await _identityClaimTypeRepository.UpdateAsync(claimType);
{
await _identityClaimTypeRepository.DeleteAsync(id);
} }
} }
} }

17
modules/identity/src/Volo.Abp.Identity.EntityFrameworkCore/Volo/Abp/Identity/EntityFrameworkCore/EfCoreIdentityClaimTypeRepository.cs

@ -1,10 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.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; return await DbSet.WhereIf(claimTypeId != null, ct => ct.Id == claimTypeId).CountAsync(ct => ct.Name == name) > 0;
} }
public async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
var identityClaimTypes = await DbSet.OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToListAsync();
return identityClaimTypes;
}
public async Task<int> GetTotalCount()
{
return await DbSet.CountAsync();
}
} }
} }

16
modules/identity/src/Volo.Abp.Identity.MongoDB/Volo/Abp/Identity/MongoDB/MongoIdentityClaimTypeRepository.cs

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Linq.Dynamic.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; 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; return GetMongoQueryable().WhereIf(claimTypeId != null, ct => ct.Id == claimTypeId).Count(ct => ct.Name == name) > 0;
} }
public async Task<List<IdentityClaimType>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
var identityClaimTypes = GetMongoQueryable().OrderBy(sorting ?? "name desc")
.PageBy(skipCount, maxResultCount)
.ToList();
return identityClaimTypes;
}
public async Task<int> GetTotalCount()
{
return await GetMongoQueryable().CountAsync();
}
} }
} }

Loading…
Cancel
Save