Created basic UserAppService.

pull/112/head
Halil İbrahim Kalkan 8 years ago
parent 0767c8441b
commit f0cb66a518

@ -247,7 +247,7 @@ namespace Volo.Abp.AspNetCore.Mvc
protected virtual string CalculateUrl(string rootPath, string controllerName, ActionModel action, string httpMethod)
{
var url = $"api/{rootPath}/{controllerName}";
var url = $"api/{rootPath}/{controllerName.ToCamelCase()}";
//Add {id} path if needed
if (action.Parameters.Any(p => p.ParameterName == "id"))

@ -112,5 +112,10 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
DbSet.Remove(entity);
}
}
public override Task<long> GetCountAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return GetQueryable().LongCountAsync(cancellationToken);
}
}
}

@ -1,14 +1,11 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
namespace Volo.Abp.Identity
{
public interface IUserAppService : IApplicationService
public interface IUserAppService : IAsyncCrudAppService<IdentityUserDto, Guid, PagedAndSortedResultRequestDto, IdentityUserCreateOrUpdateDto>
{
Task<ListResultDto<IdentityUserDto>> Get();
Task<IdentityUserDto> Get(Guid id);
}
}

@ -0,0 +1,17 @@
namespace Volo.Abp.Identity
{
public class IdentityUserCreateOrUpdateDto
{
public string UserName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public bool TwoFactorEnabled { get; set; }
public bool LockoutEnabled { get; set; }
public string Password { get; set; }
}
}

@ -1,4 +1,5 @@
using Volo.Abp.Application.Dtos;
using System;
using Volo.Abp.Application.Dtos;
namespace Volo.Abp.Identity
{
@ -7,5 +8,17 @@ namespace Volo.Abp.Identity
public string UserName { get; set; }
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public bool TwoFactorEnabled { get; set; }
public DateTimeOffset? LockoutEnd { get; set; }
public bool LockoutEnabled { get; set; }
}
}

@ -10,27 +10,66 @@ namespace Volo.Abp.Identity
public class UserAppService : ApplicationService, IUserAppService
{
private readonly IdentityUserManager _userManager;
private readonly IIdentityUserRepository _userRepository;
public UserAppService(IIdentityUserRepository userRepository)
public UserAppService(IdentityUserManager userManager, IIdentityUserRepository userRepository)
{
_userManager = userManager;
_userRepository = userRepository;
}
public async Task<ListResultDto<IdentityUserDto>> Get()
public async Task<IdentityUserDto> GetAsync(Guid id)
{
var users = await _userRepository.GetListAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(
await _userManager.GetByIdAsync(id)
);
}
return new ListResultDto<IdentityUserDto>(
ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(users)
public async Task<PagedResultDto<IdentityUserDto>> GetListAsync(PagedAndSortedResultRequestDto input)
{
var userCount = (int) await _userRepository.GetCountAsync();
var userDtos = ObjectMapper.Map<List<IdentityUser>, List<IdentityUserDto>>(
await _userRepository.GetListAsync(input.Sorting, input.MaxResultCount, input.SkipCount)
);
return new PagedResultDto<IdentityUserDto>(userCount, userDtos);
}
public async Task<IdentityUserDto> Get(Guid id)
public async Task<IdentityUserDto> CreateAsync(IdentityUserCreateOrUpdateDto input)
{
var user = await _userRepository.GetAsync(id);
var user = new IdentityUser(GuidGenerator.Create(), input.UserName);
await UpdateUserProperties(input, user);
await _userManager.CreateAsync(user, input.Password);
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
public async Task<IdentityUserDto> UpdateAsync(Guid id, IdentityUserCreateOrUpdateDto input)
{
var user = await _userManager.GetByIdAsync(id);
await _userManager.SetUserNameAsync(user, input.UserName);
await UpdateUserProperties(input, user);
await CurrentUnitOfWork.SaveChangesAsync();
return ObjectMapper.Map<IdentityUser, IdentityUserDto>(user);
}
public async Task DeleteAsync(Guid id)
{
var user = await _userManager.GetByIdAsync(id);
await _userManager.DeleteAsync(user);
}
private async Task UpdateUserProperties(IdentityUserCreateOrUpdateDto input, IdentityUser user)
{
await _userManager.SetEmailAsync(user, input.Email);
await _userManager.SetPhoneNumberAsync(user, input.PhoneNumber);
await _userManager.SetTwoFactorEnabledAsync(user, input.TwoFactorEnabled);
await _userManager.SetLockoutEnabledAsync(user, input.LockoutEnabled);
}
}
}

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Threading;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
@ -76,5 +77,10 @@ namespace Volo.Abp.Identity
return await query.ToListAsync(cancellationToken);
}
public async Task<List<IdentityUser>> GetListAsync(string sorting, int maxResultCount, int skipCount)
{
return await this.OrderBy(sorting ?? "UserName").PageBy(skipCount, maxResultCount).ToListAsync();
}
}
}

@ -1,5 +1,6 @@
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
@ -16,7 +17,7 @@ namespace Volo.Abp.Identity.Web.Areas.Identity.Controllers
public async Task<ActionResult> Index()
{
var result = await _userAppService.Get();
var result = await _userAppService.GetListAsync(new PagedAndSortedResultRequestDto());
return View(result.Items);
}
}

@ -18,8 +18,12 @@ namespace Volo.Abp.Identity
Task<IdentityUser> FindByNormalizedEmailAsync([NotNull] string normalizedEmail, CancellationToken cancellationToken);
//TODO: Why not return List instead of IList
Task<IList<IdentityUser>> GetListByClaimAsync(Claim claim, CancellationToken cancellationToken);
//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);
}
}

@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Services;
namespace Volo.Abp.Identity
@ -31,5 +33,16 @@ namespace Volo.Abp.Identity
{
}
public async Task<IdentityUser> GetByIdAsync(Guid id)
{
var user = await Store.FindByIdAsync(id.ToString(), CancellationToken);
if (user == null)
{
throw new EntityNotFoundException(typeof(IdentityUser), id);
}
return user;
}
}
}

@ -120,5 +120,10 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
{
return Collection.AsQueryable();
}
public override Task<long> GetCountAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return Collection.CountAsync(Builders<TEntity>.Filter.Empty, cancellationToken: cancellationToken);
}
}
}

@ -18,28 +18,27 @@ namespace Volo.Abp.Application.Services
}
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetListInput, TEntityDto, TEntityDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput, in TCreateInput>
: IAsyncCrudAppService<TEntityDto, TPrimaryKey, TGetListInput, TCreateInput, TCreateInput>
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
{
}
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
public interface IAsyncCrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput, in TCreateInput, in TUpdateInput>
: IApplicationService
where TEntityDto : IEntityDto<TPrimaryKey>
{
Task<TEntityDto> GetAsync(TPrimaryKey id);
Task<PagedResultDto<TEntityDto>> GetListAsync(TGetAllInput input);
Task<PagedResultDto<TEntityDto>> GetListAsync(TGetListInput input);
Task<TEntityDto> CreateAsync(TCreateInput input);

@ -17,28 +17,27 @@ namespace Volo.Abp.Application.Services
}
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TEntityDto, TEntityDto>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetListInput, TEntityDto, TEntityDto>
where TEntityDto : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetAllInput, TCreateInput, TCreateInput>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput, in TCreateInput>
: ICrudAppService<TEntityDto, TPrimaryKey, TGetListInput, TCreateInput, TCreateInput>
where TEntityDto : IEntityDto<TPrimaryKey>
where TCreateInput : IEntityDto<TPrimaryKey>
{
}
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetAllInput, in TCreateInput, in TUpdateInput>
public interface ICrudAppService<TEntityDto, in TPrimaryKey, in TGetListInput, in TCreateInput, in TUpdateInput>
: IApplicationService
where TEntityDto : IEntityDto<TPrimaryKey>
{
TEntityDto Get(TPrimaryKey id);
PagedResultDto<TEntityDto> GetAll(TGetAllInput input);
PagedResultDto<TEntityDto> GetAll(TGetListInput input);
TEntityDto Create(TCreateInput input);

@ -133,5 +133,18 @@ namespace Volo.Abp.Domain.Repositories
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <param name="id">Primary key of the entity</param>
Task DeleteAsync(TPrimaryKey id, CancellationToken cancellationToken = default(CancellationToken));
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <returns>List of entities</returns>
long GetCount();
/// <summary>
/// Get list of all entities without any filtering.
/// </summary>
/// <param name="cancellationToken">A <see cref="T:System.Threading.CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>List of entities</returns>
Task<long> GetCountAsync(CancellationToken cancellationToken = default(CancellationToken));
}
}

@ -59,5 +59,10 @@ namespace Volo.Abp.Domain.Repositories
Delete(predicate);
return Task.CompletedTask;
}
public override long GetCount()
{
return GetQueryable().LongCount();
}
}
}

@ -86,6 +86,13 @@ namespace Volo.Abp.Domain.Repositories
return Task.CompletedTask;
}
public abstract long GetCount();
public virtual Task<long> GetCountAsync(CancellationToken cancellationToken = default(CancellationToken))
{
return Task.FromResult(GetCount());
}
protected static Expression<Func<TEntity, bool>> CreateEqualityExpressionForId(TPrimaryKey id)
{
var lambdaParam = Expression.Parameter(typeof(TEntity));

@ -165,6 +165,11 @@ namespace Volo.Abp.Domain.Repositories
throw new NotImplementedException();
}
public override long GetCount()
{
throw new NotImplementedException();
}
public override List<TEntity> GetList()
{
throw new NotImplementedException();

Loading…
Cancel
Save