Esempio n. 1
0
 private Topic GetTopic(int id)
 {
     using (var db = new News_DB())
     {
         Topic topic = db.Topics.Find(id);
         return(topic);
     }
 }
Esempio n. 2
0
 private News GetNewsText(int id)
 {
     using (var db = new News_DB())
     {
         News news = db.News.Find(id);
         return(news);
     }
 }
Esempio n. 3
0
        private List <Comment> GetComments(int id)
        {
            List <Comment> comments = new List <Comment>();

            using (var db = new News_DB())
            {
                comments = db.Comments.Where(x => x.NewsId == id).ToList();
            }
            return(comments);
        }
Esempio n. 4
0
        private List <Topic> TopicList()
        {
            List <Topic> topics = new List <Topic>();

            using (var db = new News_DB())
            {
                topics = db.Topics.ToList();
            }
            return(topics);
        }
Esempio n. 5
0
        private List <News> GetTopics(int id)
        {
            List <News> news = new List <News>();

            using (var db = new News_DB())
            {
                news = db.News.Where(x => x.TopicId == id).ToList();
            }
            return(news);
        }
Esempio n. 6
0
        public ActionResult Main()
        {
            List <News> news = new List <News>();

            using (var db = new News_DB())
            {
                news = db.News.OrderByDescending(d => d.Date).ToList();
            }
            return(View(news));
        }
Esempio n. 7
0
        public ActionResult DeleteComment(int commentId, int newsId)
        {
            using (var db = new News_DB())
            {
                db.Comments.Remove(db.Comments.Find(commentId));

                db.SaveChanges();
            }
            return(RedirectToAction("NewsText", new { id = newsId }));
        }
Esempio n. 8
0
        public ActionResult DeleteNews(int newsId)
        {
            using (var db = new News_DB())
            {
                db.Comments.RemoveRange(db.Comments.Where(c => c.NewsId == newsId));
                db.News.Remove(db.News.Find(newsId));

                db.SaveChanges();
            }
            return(RedirectToAction("Main"));
        }
Esempio n. 9
0
 public ActionResult NewComment(Comment newComment)
 {
     if (ModelState.IsValid)
     {
         using (var db = new News_DB())
         {
             newComment = db.Comments.Add(new Models.Comment()
             {
                 Name     = newComment.Name,
                 Comments = newComment.Comments,
                 NewsId   = newComment.NewsId
             });
             db.SaveChanges();
         }
     }
     return(RedirectToAction("NewsText", new { id = newComment.NewsId }));
 }
Esempio n. 10
0
 public ActionResult NewNews(News news)
 {
     if (ModelState.IsValid)
     {
         using (var db = new News_DB())
         {
             news = db.News.Add(new Models.News()
             {
                 Name    = news.Name,
                 Author  = news.Author,
                 Article = news.Article,
                 Date    = news.Date,
                 Picture = "/Content/Placeholder.png",
                 TopicId = news.TopicId
             });
             db.SaveChanges();
         }
         return(RedirectToAction("NewsText", new { id = news.Id }));
     }
     return(View());
 }