public JsonResult getNew(int id) { TopicService sertop = new TopicService(); MappingService sermap = new MappingService(); NewspaperService sernews = new NewspaperService(); if (id == 0) { return(Json(sernews.GetAll(), JsonRequestBehavior.AllowGet)); } else { var query = (from tp in sertop.GetAll() join map in sermap.GetAll() on tp.TopicId equals map.TopicId join news in sernews.GetAll() on map.NewsId equals news.NewsId where tp.TopicId == id select new { news.Image, news.Title, tp.TopicName, news.NewsId }).ToList(); ViewBag.getbaotheoIDTopic = query; return(Json(query, JsonRequestBehavior.AllowGet)); } }
public JsonResult getNew(int id) { var query = (from tp in sertop.GetAll() join map in sermap.GetAll() on tp.TopicId equals map.TopicId join news in serNews.GetAll() on map.NewsId equals news.NewsId where tp.TopicId == id select new { news.Image, news.Title, tp.TopicName, news.NewsId }).ToList(); ViewBag.getbaotheoIDTopic = query; return(Json(query, JsonRequestBehavior.AllowGet)); }
public ActionResult UpdateNews(int newsid = 11) { if (Session["account"] is null) { return(RedirectToAction("Login", "Login")); } else { var account = Session["account"] as Account; NewspaperService svn = new NewspaperService(); var result = svn.GetById(newsid); MappingService svm = new MappingService(); var mapresult = svm.GetAll().Where(x => x.NewsId == result.NewsId).ToList(); List <Topic> lsttopic = new List <Topic>(); TopicService svt = new TopicService(); foreach (var item in mapresult) { lsttopic.Add(svt.GetById(item.TopicId)); } string str = ""; foreach (var item in lsttopic) { str += item.TopicId + ","; } str = str.Substring(0, str.Length - 1); ViewBag.GetTopic = str; NewInfo newinfo = new NewInfo(); newinfo.Title = result.Title; newinfo.NewsId = result.NewsId; newinfo.Image = result.Image; newinfo.Journalist = account.AccountName; newinfo.Description = result.Description; newinfo.Topic = svt.GetAll().ToList(); return(View(newinfo)); } }
public ActionResult UpdateNews(NewInfo info, FormCollection f) { if (Session["account"] is null) { return(RedirectToAction("Login", "Login")); } else { var account = Session["account"] as Account; var listtopic = f["topicstring"].ToString().Split(new char[] { ',' }); Newspaper news = new Newspaper(); NewspaperService svn = new NewspaperService(); news.PublicationDate = DateTime.Now; news.Active = 0; news.NewsId = info.NewsId; news.Title = info.Title; news.Image = info.Image; news.Description = info.Description; news.Journalist = account.AccountName; svn.UpdateNewspaper(news); MappingService svm = new MappingService(); var getm = svm.GetAll().Where(x => x.NewsId == news.NewsId); var s = getm.ToList().Count; foreach (var item in getm.ToList()) { svm.DeleteMapping(item.MappingId); } foreach (var item in listtopic) { svm.AddMapping(new Mapping { NewsId = info.NewsId, TopicId = Int32.Parse(item) }); } return(RedirectToAction("UpdateNews")); } }