private Topic GetTopic(int id) { using (var db = new News_DB()) { Topic topic = db.Topics.Find(id); return(topic); } }
private News GetNewsText(int id) { using (var db = new News_DB()) { News news = db.News.Find(id); return(news); } }
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); }
private List <Topic> TopicList() { List <Topic> topics = new List <Topic>(); using (var db = new News_DB()) { topics = db.Topics.ToList(); } return(topics); }
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); }
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)); }
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 })); }
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")); }
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 })); }
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()); }