using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using Weee.DAL; using Weee.Models; using PagedList; namespace Weee.Areas.Admin.Controllers { public class PublicMessageController : AdminControllerBase { public PublicMessageController(WeeeDataContext db) : base(db) { } public ActionResult Index(int page = 1) { var publicMsgs = db.PublicMessages.ToList(); var onePageOfPublicMsgs = publicMsgs.ToPagedList(page, 10); return View(onePageOfPublicMsgs); } public ActionResult Edit(int id) { var toBeEdit = db.PublicMessages.Find(id); if (toBeEdit == null) toBeEdit = new Models.PublicMessage(); return View(toBeEdit); } [HttpPost] [ValidateAntiForgeryToken] public ActionResult Edit(PublicMessage toBeEdit) { if (ModelState.IsValid) { var entry = db.Entry(toBeEdit); if (toBeEdit.ID == 0) entry.State = EntityState.Added; else { entry.State = EntityState.Modified; entry.Property(x => x.CreatedTime).IsModified = false; } db.SaveChanges(); return RedirectToAction("Index"); } return View(toBeEdit); } } }