public async Task <IActionResult> Delete(PostDeleteInputModel input) { var postId = await this.postsService.DeleteAsync(input.PostId); if (postId == null) { return(this.NotFound()); } this.TempData["InfoMessage"] = "Post deleted successfully!"; return(this.Redirect("/Administration/Posts/Index")); }
public async Task <IActionResult> Delete(PostDeleteInputModel input) { if (input.AuthorUserName != this.User.Identity.Name) { return(this.BadRequest()); } var post = this.postsRepository.All().Where(x => x.Id == input.Id).FirstOrDefault(); var category = this.categoriesService.GetAll <CategoryDropdownViewModel>().Where(x => x.Id == input.CategoryId).FirstOrDefault().Name; this.postsRepository.Delete(post); await this.postsRepository.SaveChangesAsync(); return(this.Redirect($"/c/{category}")); }