public IActionResult DeletePost([FromBody] PostControlPanelViewModel viewModel) { if (ModelState.IsValid) { var post = postService.GetPostById(viewModel.Id); if (post.Image.Base64 != null) { post.Image.Delete(); } postService.RemovePost(post); if (postService.SaveAll()) { logger.LogInformation($"{post.Title} no longer exists."); return(Ok()); } } logger.LogError($"Failed to remove: {viewModel.Title}"); return(BadRequest()); }
public IActionResult ApprovePost([FromBody] PostControlPanelViewModel viewModel) { if (ModelState.IsValid) { //get an existing post then set isPublished status var post = postService.GetPostById(viewModel.Id); post.IsPublished = true; if (post.Image.Base64 != null) { post.Image.ToImage(); } postService.UpdatePost(post); if (postService.SaveAll()) { logger.LogInformation($"{post.Title} is published."); return(Ok()); } } logger.LogError($"Failed to publish: {viewModel.Title}"); return(BadRequest()); }