Beispiel #1
0
        public ActionResult CategoryCreate(NewsCategory category)
        {
            if (ModelState.IsValid)
            {
                //if category exsits we do not need to create it
                var cat = db.NewsCategories.Select(c => c.Name);
                if(cat.Contains(category.Name))
                    return RedirectToAction("CategoryIndex");

                db.NewsCategories.Add(category);
                db.SaveChanges();
                return RedirectToAction("CategoryIndex");
            }
            else
            {
                return View(category);
            }
        }
Beispiel #2
0
 public ActionResult CategoryEdit(NewsCategory newscategory)
 {
     if (ModelState.IsValid)
     {
         var category = db.NewsCategories.Find(newscategory.ID);
         if (category != null)
         {
             //db.Entry(newscategory).State = EntityState.Modified;
             category.Name = newscategory.Name;
             UpdateModel(category);
             db.SaveChanges();
             return RedirectToAction("CategoryIndex");
         }
     }
     return View(newscategory);
 }