public ActionResult SaveItemsToPackage(string ids,string packageId)
        {
            int packId = Convert.ToInt32(packageId);
            List<PackageItem> objPackList = db.PackageItems.Where(pi => pi.PackageID == packId).ToList();

            string[] splittedIds = ids.Split(',');
            foreach (var item in splittedIds)
            {
                if (!string.IsNullOrEmpty(item))
                {
                    long pItem = Convert.ToInt64(item);
                    PackageItem product = db.PackageItems.SingleOrDefault(p => p.MenuID == pItem && p.PackageID == packId);
                    if (product != null)
                    {
                        product.IsDeleted = false;
                        db.ObjectStateManager.ChangeObjectState(product, System.Data.EntityState.Modified);
                        db.SaveChanges();
                    }
                    else
                    {
                        PackageItem objpack = new PackageItem();
                        objpack.PackageID = packId;
                        objpack.MenuID = Convert.ToInt64(item);

                        db.PackageItems.AddObject(objpack);
                        db.SaveChanges();
                        
                    }
                }
            }

            foreach (var item in objPackList)
            {
                string val = Convert.ToString(item.MenuID);
               if(!splittedIds.Contains(val))
                {
                    
                        PackageItem product = db.PackageItems.SingleOrDefault(p => p.MenuID == item.MenuID && p.PackageID == packId);
                        if (product != null)
                        {
                            product.IsDeleted = true;
                            db.ObjectStateManager.ChangeObjectState(product, System.Data.EntityState.Modified);
                            db.SaveChanges();
                        }
                    
                }
            }


            var result = new { Success = "True" };
            return Json(result, JsonRequestBehavior.AllowGet);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the PackageItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPackageItems(PackageItem packageItem)
 {
     base.AddObject("PackageItems", packageItem);
 }
 /// <summary>
 /// Create a new PackageItem object.
 /// </summary>
 /// <param name="packageItemID">Initial value of the PackageItemID property.</param>
 public static PackageItem CreatePackageItem(global::System.Int64 packageItemID)
 {
     PackageItem packageItem = new PackageItem();
     packageItem.PackageItemID = packageItemID;
     return packageItem;
 }