Пример #1
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);
        }
Пример #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);
        }
Пример #3
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);
        }