コード例 #1
0
 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);
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
 }
コード例 #4
0
 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));
 }
コード例 #5
0
        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();
            }
        }
コード例 #6
0
        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);
            }
        }