public async Task <CosmosPostDto> AddNewPostAsync(CreateCosmosPostDto newPost) { if (string.IsNullOrEmpty(newPost.Title)) { throw new Exception("Post can not have empty title."); } var post = _mapper.Map <CosmosPost>(newPost); var result = await _postRepository.AddAsync(post); return(_mapper.Map <CosmosPostDto>(result)); }
public async Task <IActionResult> CreateAsync(CreateCosmosPostDto newPost) { var post = await _postService.AddNewPostAsync(newPost); return(Created($"api/posts/{post.Id}", post)); }