public ActionResult Update(NewsCategory model)
 {
     var NewsCategory = db.NewsCategory.FirstOrDefault(i => i.Id == model.Id);
     NewsCategory.Name = model.Name;
     db.Entry(NewsCategory).State = EntityState.Modified;
     db.SaveChanges();
     return Json("OK", JsonRequestBehavior.AllowGet);
 }
 public ActionResult Update(NewsCategory model)
 {
     var page = db.NewsCategory.FirstOrDefault(i => i.Id == model.Id);
     page.Content = model.Content;
     db.Entry(page).State = EntityState.Modified;
     db.SaveChanges();
     return Json("OK", JsonRequestBehavior.AllowGet);
 }
 public ActionResult Page(string PageName)
 {
     var page = new NewsCategory();
     foreach (var item in db.NewsCategory.Where(i=>i.GroupID =="page"))
     {
         if (Exts.ToAscii(item.Name) == PageName)
         {
             page = item;
         }
     }
     return View(page);
 }
 public ActionResult NewsByCategory(string CategoryName)
 {
     var category = new NewsCategory();
     foreach (var item in db.NewsCategory)
     {
         if (Exts.ToAscii(item.Name) == CategoryName)
         {
             category = item;
             break;
         }
     }
     ViewBag.categoryName = category.Name;
     return View(db.News.Where(i => i.CategoryId == category.Id));
 }
        public ActionResult Add(NewsCategory model)
        {
            if (!string.IsNullOrEmpty(model.Name))
            {
                model.GroupID = "page";
                db.NewsCategory.Add(model);
                db.SaveChanges();

                var recentAdded = (db.NewsCategory.Where(i => i.GroupID == "page").OrderByDescending(i => i.Id)).FirstOrDefault();
                return Json(recentAdded, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return HttpNotFound();
            }
        }
        public ActionResult Add(NewsCategory model)
        {
            if (ModelState.IsValid)
            {
                model.Order = db.NewsCategory.Where(i => i.GroupID == "NewsC").Max(i => i.Order) +1;
                model.GroupID = "NewsC";
                db.NewsCategory.Add(model);
                db.SaveChanges();

                var recentAdded = (db.NewsCategory.Where(i => i.GroupID == "NewsC").OrderByDescending(i => i.Id)
                                    .Select(nc => new { Id = nc.Id, Name = nc.Name, TotalNews = nc.Newss.Count() })).FirstOrDefault();
                return Json(recentAdded,JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json("error", JsonRequestBehavior.AllowGet);
            }
        }