コード例 #1
0
 public ActionResult NewsList()
 {
     using (var context = new WebDbContext())
     {
         return View(context.News.ToList());
     }
 }
コード例 #2
0
 public ActionResult NewsEdit(int id) 
 {
     using (var c = new WebDbContext())
     {
         var post = c.News.Find(id);
         if (post == null) return new HttpNotFoundResult();
         NewsViewModel mdl = new NewsViewModel();
         mdl.Id = post.Id;
         mdl.ImageFile = post.Image;
         mdl.Title = post.Title;
         mdl.HtmlContent = post.HtmlContent;
         return View(mdl);
     } 
 }
コード例 #3
0
 public ActionResult NewsEdit(NewsViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var c = new WebDbContext())
         {
             var oPost = c.News.Find(model.Id);
             oPost.HtmlContent = model.HtmlContent;
             oPost.Image = model.ImageFile;
             oPost.Title = model.Title;
             oPost.Date = DateTime.Now;
             c.SaveChanges();
         }
         GameCache.ReCache(false, false, true);
         return RedirectToAction("NewsList");
     }
     return View(model);
 }
コード例 #4
0
 public ActionResult NewsCreate(NewsViewModel model)
 {
     if (ModelState.IsValid)
     {
         NewsPost npost = new NewsPost();
         npost.Date = DateTime.Now;
         npost.Title = model.Title;
         npost.Image = model.ImageFile;
         npost.Shares = 0;
         npost.HtmlContent = model.HtmlContent;
         npost.Author = "Admin";
         using (var c = new WebDbContext())
         {
             c.News.Add(npost);
             c.SaveChanges();
         }
         GameCache.ReCache(false, false, true);
     }
     
     return RedirectToAction("NewsList","Admin");
 }
コード例 #5
0
 public ActionResult NewsDelete(int id)
 {
     using (var c = new WebDbContext())
     {
         c.News.Remove(c.News.Find(id));
         c.SaveChanges();
     }
     GameCache.ReCache(false, false, true);
     return RedirectToAction("NewsList");
 }