public async Task <IActionResult> Post(CreateStoryModel model) { try { return(Ok(await _storyService.CreateStory(model.WorldId, model.Title))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <IActionResult> Create([FromBody] CreateStoryModel model) { if (false == ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await mediator.Send( new CreateStoryCommand(User, model.Title, model.Content, model.IsPublic), HttpContext.RequestAborted ); if (false == result.IsSuccess()) { foreach (var exception in result.Exceptions) { logger.LogError(exception, "[StoriesController.Create]"); } return(BadRequest(result.Exceptions)); } await commandBus.SendAsync(new StoryCreatedIntegrationCommand { Id = Guid.NewGuid(), StoryId = result.Data.Id, Sent = result.Data.Created }); logger.StoryCreated(result.Data.Id); return(Created( Url.Action("Get", "Story", new { slug = result.Data.Slug }), mapper.Map <StoryModel>(result.Data) )); }