public async Task DeletePost(Posts post) { var target = forumDbContext.Posts .Include(x => x.ChildrenPosts) .FirstOrDefault(x => x.ParentId == post.PostId); if (target != null) { RecursiveDelete(target); } forumDbContext.Remove(post); await forumDbContext.SaveChangesAsync(); }
public void Delete(int id) { var user = context.Users.Find(id); context.Remove(user); context.SaveChanges(); }
public void Delete(int id) { var user = this.ById(id); context.Remove(user); context.SaveChanges(); }
public IActionResult Delete(int id) { Topic topic = context.Topics .Include(t => t.Author) .SingleOrDefault(m => m.Id == id); if (topic != null) { context.Remove(topic); context.SaveChanges(); } return(RedirectToAction("Index", "Home")); }
public async Task <Result <object> > Handle(DeleteAvatarCommand request, CancellationToken cancellationToken) { var profile = await _forumDbContext.Profiles .IncludeUser() .SingleAsync(p => p.UserId == request.UserId); var avatar = profile.Avatar; if (avatar == null) { return(Result <object> .Failure(string.Empty, "Avatar doesn't exist")); } _forumDbContext.Remove(avatar); await _photoStorage.DeletePhotoAsync(avatar.FileName); await _forumDbContext.SaveChangesAsync(); return(Result <object> .Success()); }