Exemplo n.º 1
0
 public ActionResult Update(Category category)
 {
     if (!ModelState.IsValid) return View();
     _db.Entry(category).State = EntityState.Modified;
     _db.SaveChanges();
     return RedirectToAction("AddNewCategory");
 }
Exemplo n.º 2
0
        public ActionResult AddNewCategory(Category category)
        {

            if (ModelState.IsValid)
            {
                if (!_db.Category.Any(m=>m.CategoryName.Equals(category.CategoryName)))
                {
                    _db.Category.Add(category);
                    _db.SaveChanges();
                    ViewBag.successMsg = "New category has been added successfully";
                    ViewBag.emptyId = 1;

                }
                else
                {
                  ModelState.AddModelError("","Category name already exist!");  
                }
            
            }
            ViewData["GetCategories"] = from c in _db.Category
                                        select new CategoryViewModel() { CategoryId = c.CategoryId, CategoryName = c.CategoryName };
            ViewBag.successMseeageShowId = 1;
            return View();

        }