public bool DeletePage(Task <PagesTB> pages) { try { _db.Remove(pages); return(true); } catch { return(false); } }
public bool DeleteGroup(Task <PageGroups> groups) { try { _db.Remove(groups); return(true); } catch { return(false); } }
public IActionResult Delete(int id) { Article article = context.Articles.FirstOrDefault(p => p.ArticleId == id); if (article == null) { return(NotFound()); } context.Remove(article); context.SaveChanges(); return(Ok(article)); }
public async Task <int> Delete(int id) { //use TransactionScope var article = await _context.Articles .Include(a => a.Content) .FirstOrDefaultAsync(a => a.Id == id); var comments = await _context.Comments .Where(c => c.Article.Id == id).ToListAsync(); var ratings = await _context.Ratings .Where(r => r.Article.Id == id).ToListAsync(); if (article != null) { comments.ForEach(c => _context.Remove(c)); ratings.ForEach(r => _context.Remove(r)); _context.Remove(article); _context.Remove(article.Content); } return(await _context.SaveChangesAsync()); }
public JsonResult DeleteArticle(int articleID) { var article = _context.Article.Where(a => a.ArticleID == articleID).FirstOrDefault(); if (article != null) { _context.Remove(article); _context.SaveChanges(); //Note: It's not certain from assignment description that if we sould clear the ArticleLike data for deleted article. //Thus; did not implemented that part } return(Json(new { result = true })); }
public async Task <ActionResult> Delete(int id) { var news = await _context.Set <News>().FirstOrDefaultAsync(n => n.Id == id); if (news == null) { return(NotFound()); } _context.Remove(news); await _context.SaveChangesAsync(); _eventBus.Publish(new NewsRemoveEvent(id)); return(NoContent()); }
public IActionResult RemoveNews(int?newsid) { using (var client = new NewsContext()) { var result = client.News.Single(x => x.Id == newsid.Value); client.Remove(result); client.SaveChanges(); } var removedMessage = string.Format("Nyheten med ID {0} togs bort", newsid); return(Json(new { success = true, Message = removedMessage })); }
//=============================== DELETE POST public bool DeletePost(int id) { var post = _context.News.FirstOrDefault(x => x.id == id); var imageName = post.FileName; _context.Remove(post); var result = _context.SaveChanges(); var rootPath = Path.Combine(_webHost.WebRootPath, "images", "PostsGallery", imageName); File.Delete(rootPath); if (result > 0) { return(true); } else { return(false); } }