public async Task <IActionResult> GetAsync(int id) { if (id <= 0) { return(BadRequest(Result.Failed((int)HttpStatusCode.BadRequest, "Id can not be less that 1."))); } var query = new GetBucketQuery(id); var result = await _queryExecutor.ExecuteAsync <GetBucketQuery, BucketDocument>(query); return(Ok(result)); }
public async Task <IActionResult> CreateAsync([FromBody] CreateBucketRequestDocument document) { var command = _mapper.MapFrom <CreateBucketRequestDocument, CreateBucketCommand>(document); var commandResult = await _commandExecutor.ExecuteAsync <CreateBucketCommand, int>(command); if (commandResult.IsFailed) { return(BadRequest(commandResult)); } var query = new GetBucketQuery(commandResult.Value); var queryResult = await _queryExecutor.ExecuteAsync <GetBucketQuery, BucketDocument>(query); if (queryResult.IsFailed) { return(BadRequest(queryResult)); } // ReSharper disable once Mvc.ActionNotResolved return(CreatedAtAction(nameof(GetAsync), new { id = queryResult.Value !.Id }, queryResult));