public async Task CreateAsync(CreateUserAdto createUserAdto) { using (ITransaction transaction = _transactionManager.Create()) { Identity identity = await _queryRepository.GetByIdAsync(createUserAdto.IdentityId); try { User user = await _createUserCommand.ExecuteAsync(new CreateUserCommandDdto { Identity = identity }); await _commandRepository.AddAsync(user); } catch (CreateDomainException e) { throw new BusinessApplicationException(ExceptionType.Unknown, e); } catch (ConcurrencyDomainException e) { throw new BusinessApplicationException(ExceptionType.Concurrency, e); } catch (DomainValidationRuleException e) { throw new BusinessValidationRuleApplicationException(e.ValidationResult); } transaction.Commit(); } }
public async Task <IActionResult> Register(CreateUserRequest user, [FromServices] ICreateUserCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { UserResponse response = await command.ExecuteAsync(user); return(CreatedAtRoute("GetSingleUser", new { userId = response.Id }, response)); } catch (CannotCreateUserExeption exception) { foreach (var error in exception.Errors) { ModelState.AddModelError(exception.Message, error.Description); } return(BadRequest(ModelState)); } }
public Task HandleAsync(RegistrationCompletedEvent @event) { // Create a new user when a registration is made return(createUserCommand.ExecuteAsync(@event.Email)); }