Ejemplo n.º 1
0
 protected async Task CommitAsync()
 {
     if (!_notificationProvider.HasErrors())
     {
         await _repository.CommitAsync();
     }
 }
Ejemplo n.º 2
0
        public override async Task <UserDto> PostAsync(UserCreateCommand command)
        {
            if (!CheckRules <UserRegisterCommandValidation, UserCreateCommand>(command))
            {
                return(null);
            }

            //criar metodo repository de buscar por login
            if (_userRepository.GetByLogin(command.Login) != null)
            {
                _notificationProvider.AddValidationError("Login", "Já existe um usuário com este login");
            }


            if (_notificationProvider.HasErrors())
            {
                return(null);
            }


            //valida os dados
            //encriptar password
            var user = new User(command.Login, command.Name, command.Email)
                       .CreatePassword(command.Password, _encrypterService);

            if (CheckRules <UserValidation, User>(user))
            {
                await _repository.InsertAsync(user);
            }

            await CommitAsync();


            return(_mapper.Map <UserDto>(user));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Login(AuthCommand command)
        {
            var result = _appService.Login(command);

            if (_notificationProvider.HasErrors())
            {
                return(BadRequest(new FailedResult("Bad Request", _notificationProvider.GetErrors())));
            }

            return(Ok(result));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Post(UserCreateCommand command)
        {
            var result = await _appService.PostAsync(command);

            if (_notificationProvider.HasErrors())
            {
                return(BadRequest(new FailedResult("Bad Request", _notificationProvider.GetErrors())));
            }

            return(Ok(result));
        }