public IActionResult CreateUserPost(int userId, [FromBody] Post post) { var cmd = new CreateUserPostCommand(userId, post); var result = commandProcessor.Process(cmd); if (!result.Success) { return(BadRequest()); //TODO: Not accurate } return(Ok(result.Response)); }
public CommandResult <Post> Handle(CreateUserPostCommand command) { var result = new CommandResult <Post>(); try { var authorId = command.UserId; var post = command.Post; post.AuthorId = authorId; ctx.Posts.Add(post); ctx.SaveChanges(); result.Success = true; result.Response = post; } catch (Exception e) { logger.LogError(e.Message); } return(result); }