Exemplo n.º 1
0
        public async Task <PaginationDto <UserDto> > HandleAsync(GetUsersQuery query)
        {
            var count = await _context.Users.Where(query).CountAsync();

            var users = await _context.Users.FilterBy(query).ToListAsync();

            var wrapper = new PaginationDto <User> {
                Data = users, TotalCount = count
            };

            return(_mapper.MapTo <PaginationDto <UserDto> >(wrapper));
        }
Exemplo n.º 2
0
        public async Task HandleAsync(UserRegisterCommand command)
        {
            var user = await _swizzerContext.Users.FirstOrDefaultAsync(x => x.Email == command.Email);

            if (user != null)
            {
                throw new SwizzerServerException(ServerErrorCodes.InvalidParamter, $"User with email {command.Email} already exists");
            }

            user      = _mapper.MapTo <UserRegisterCommand, User>(command);
            user.Salt = _securityService.GetSalt();
            user.Hash = _securityService.GetHash(command.Password, user.Salt);

            await _swizzerContext.AddAsync(user);
        }
Exemplo n.º 3
0
        public async Task HandleAsync(CreateMessageCommand command)
        {
            var message = _swizzerMapper.MapTo <Message>(command);

            message.ReceiverId = command.Receiver;
            message.SenderId   = command.RequestBy;

            await _context.AddAsync(message);
        }
Exemplo n.º 4
0
        public async Task HandleAsync(CreateUserCommand command)
        {
            var user = await _swizzerContext.Users.FirstOrDefaultAsync(x => x.Email == command.Email);

            if (user != null)
            {
                throw new SwizzerServerException(ErrorCode.InvalidParameter, $"{command.Email} already exist with ${user.Id}");
            }

            user = _swizzerMapper.MapTo <User>(command);

            user.Salt = _seciurityService.GetSalt();
            user.Hash = _seciurityService.GetHash(command.Password, user.Salt);

            await _swizzerContext.AddAsync(user);

            var dto = _swizzerMapper.MapTo <UserDto>(user);

            _cacheService.Set(dto);
        }
Exemplo n.º 5
0
        public async Task <PaginationDto <MessageDto> > HandleAsync(GetMessagesQuery query)
        {
            var ids      = (new[] { query.RequestBy, query.Reciever }).OrderBy(x => x).ToList();
            var querable = _context.Messages.Where(x => ids.Any(s => s == x.ReceiverId) && ids.Any(s => s == x.SenderId));
            var count    = await querable.Where(query).CountAsync();

            var data = await querable.FilterBy(query).ToListAsync();

            var wrapper = new PaginationDto <Message> {
                Data = data, TotalCount = count
            };

            return(_swizzerMapper.MapTo <PaginationDto <MessageDto> >(wrapper));
        }
Exemplo n.º 6
0
        public async Task HandleAsync(UserRegisterCommand command)
        {
            await _apiHttpWebService.SendAsync <object>(HttpMethod.Post, Routes.Users.Main, command);

            await HandleAsync(_mapper.MapTo <UserLoginCommand>(command));
        }