protected async Task CommitAsync() { if (!_notificationProvider.HasErrors()) { await _repository.CommitAsync(); } }
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)); }
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)); }
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)); }