public ActionResult NewsList() { using (var context = new WebDbContext()) { return View(context.News.ToList()); } }
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); } }
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); }
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"); }
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"); }