コード例 #1
0
 public bool DeletePage(Task <PagesTB> pages)
 {
     try
     {
         _db.Remove(pages);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #2
0
 public bool DeleteGroup(Task <PageGroups> groups)
 {
     try
     {
         _db.Remove(groups);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
コード例 #3
0
        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));
        }
コード例 #4
0
ファイル: ArticleRepository.cs プロジェクト: kevmcivor/kpmg
        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());
        }
コード例 #5
0
        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 }));
        }
コード例 #6
0
        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());
        }
コード例 #7
0
        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);
            }
        }