Ejemplo n.º 1
0
 public async Task <UserDto> Handle(GetUserByIdQuery request, CancellationToken cancellationToken)
 {
     return(await _userStorage
            .GetAll()
            .AsNoTracking()
            .Where(u => u.Id == request.UserId)
            .ProjectToSingleOrDefaultAsync <UserDto>(_mapper.ConfigurationProvider, cancellationToken)
            .ConfigureAwait(false)
            ?? throw new NotFoundException(nameof(ApplicationUser), request.UserId));
 }
Ejemplo n.º 2
0
 public async Task <RoleDto> Handle(GetRoleByIdQuery request, CancellationToken cancellationToken)
 {
     return(await _roleStorage
            .GetAll()
            .AsNoTracking()
            .Where(role => role.Id == request.RoleId)
            .ProjectToSingleOrDefaultAsync <RoleDto>(_mapper.ConfigurationProvider, cancellationToken)
            .ConfigureAwait(false)
            ?? throw new NotFoundException(nameof(ApplicationRole), request.RoleId));
 }
 public async Task <IPagedList <RoleDto> > Handle(GetPagedListOfRolesQuery request, CancellationToken cancellationToken)
 {
     return(await _roleStorage
            .GetAll()
            .AsNoTracking()
            .OrderBy(role => role.Id)
            .ProjectTo <RoleDto>(_mapper.ConfigurationProvider, cancellationToken)
            .ProjectToPagedListAsync(request, cancellationToken)
            .ConfigureAwait(false));
 }
Ejemplo n.º 4
0
            public async Task <AuthenticationResponse> Handle(AuthenticateCommand request,
                                                              CancellationToken cancellationToken)
            {
                ApplicationUser user = await _userStorage.GetAll()
                                       .Where(x => x.Email == request.Email)
                                       .Include(x => x.RefreshTokens)
                                       .SingleOrDefaultAsync(cancellationToken)
                                       ?? throw new NotFoundException(nameof(ApplicationUser), request.Email);

                (IIdentityResult, AuthenticationResponse)result = await _jwtService
                                                                  .AuthenticateAsync(user, request.Password)
                                                                  .ConfigureAwait(false);

                result.Item1.ThrowIfFailed();

                return(result.Item2);
            }