// Delete Category
 public ActionResult Delete(FormCollection form)
 {
     using (EntityContext db = new EntityContext())
     {
         try
         {
             Category category = db.Category.Find(Convert.ToInt32(form["Id"]));
             db.Category.Remove(category);
             db.SaveChanges();
             return Json(new { msg = "success" });
         }
         catch (Exception ex)
         {
             return Json(new { msg = "Fail!" + ex.Message });
         }
     }
 }
        // Batch Delete(use checkbox)
        public ActionResult BatchDelete(string ids)
        {
            using (var db = new EntityContext())
            {
                try
                {
                    var myIds=ids.Split(',').Select(x => Int32.Parse(x));
                    var query=from c in db.Category
                              where myIds.Contains(c.Id)
                              select c;

                    db.Category.RemoveRange(query);
                    db.SaveChanges();
                    return Json(new { msg = "success" });

                }
                catch (Exception ex)
                {
                    return Json(new { msg = "Fail!" + ex.Message });
                }
            }
        }
 // Add new Category
 public ActionResult Add(FormCollection form)
 {
     using (EntityContext db = new EntityContext())
     {
         if (ModelState.IsValid)
         {
             try
             {
                 Category category = new Category();
                 category.Name = form["categoryName"].Trim();
                 db.Category.Add(category);
                 db.SaveChanges();
                 return Json(new { msg = "success" });
             }
             catch (Exception ex)
             {
                 return Json(new { msg = "Fail!" + ex.Message });
             }
         }
         return Content("");
     }
 }
        // Edit Category
        public ActionResult Edit(FormCollection form)
        {
            using (EntityContext db = new EntityContext())
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        Category category = db.Category.Find(Convert.ToInt32(form["Id"]));
                        category.Name = form["Name"].Trim();

                        db.SaveChanges();
                        return Json(new { msg = "success" });
                    }
                    catch (Exception ex)
                    {
                        return Json(new { msg = "Fail!" + ex.Message });
                    }
                }
                return Content("");
            }
        }