public async Task <IActionResult> DeleteConfirmed(int id) { Post post = await repo.GetByIdAsync(id); await repo.DeleteAsync(post); return(RedirectToAction(nameof(Index))); }
public async Task DeleteAsync(Guid id) { var post = await PostRepository.GetAsync(id); await AuthorizationService.CheckAsync(post, CommonOperations.Delete); var tags = await GetTagsOfPostAsync(id); await TagRepository.DecreaseUsageCountOfTagsAsync(tags.Select(t => t.Id).ToList()); await CommentRepository.DeleteOfPost(id); await PostRepository.DeleteAsync(id); await PublishPostChangedEventAsync(post.BlogId); }
public async Task <IActionResult> DeletePost([FromRoute] int id) { // get the post to be deleted Post toBeDeleted = await Repository.FindByIdAsync(id); if (toBeDeleted is null) { return(NotFound()); } // verify the current user int userId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); if (userId != toBeDeleted.UserId) { return(BadRequest(new { Err = "You do not have permission to delete this post!" })); } // perform deletion await Repository.DeleteAsync(toBeDeleted); return(Ok()); }
/// <summary> /// 删除文章信息 /// </summary> /// <param name="ids">要删除的文章信息编号</param> /// <returns>业务操作结果</returns> public virtual Task <OperationResult> DeletePosts(params int[] ids) { Check.NotNull(ids, nameof(ids)); return(PostRepository.DeleteAsync(ids)); }