public ActionResult EditMenu(Menu objMenu)
        {
            objMenu.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList();
            objMenu.RestaurantList = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList();
            if (objMenu.SelectedPreferences == null)
                objMenu.SelectedPreferences = new int[] { };

            if (string.IsNullOrEmpty(objMenu.Name))
            {
                ModelState.AddModelError("Name", "Please enter the Name");
            }
            if (string.IsNullOrEmpty(objMenu.Type))
            {
                ModelState.AddModelError("Type", "Please enter type");
            }
            if (objMenu.Restaurant.Id <= 0)
            {
                ModelState.AddModelError("Restaurant", "Please select restaurant");
            }
            if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0)
            {
                return View(objMenu);
            }
            Menu objMenuExist = objContext.ContextMenu.Include("Restaurant").Include("MenuPreferencesList").SingleOrDefault(s => s.Id == objMenu.Id);
            objMenuExist.Name = objMenu.Name;
            objMenuExist.Type = objMenu.Type;
            objMenuExist.Restaurant = objContext.ContextRestaurant.SingleOrDefault(s => s.Id == objMenu.Restaurant.Id);
            objContext.ContextMenuPreferences.RemoveRange(objMenuExist.MenuPreferencesList);
            objMenuExist.MenuPreferencesList = new List<MenuPreferences>();
            MenuPreferences objMenuPreferences;
            foreach (int id in objMenu.SelectedPreferences)
            {
                objMenuPreferences = new MenuPreferences();
                objMenuPreferences.Preferences = objContext.ContextPreferences.Find(id);
                objMenuExist.MenuPreferencesList.Add(objMenuPreferences);
            }
            objContext.SaveChanges();
            return RedirectToAction("ListMenu");
        }
 public ActionResult CreateMenu()
 {
     if (Session["AdminId"] == null)
         return RedirectToAction("Login", "Admin");
     Menu objMenu = new Menu();
     objMenu.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList();
     objMenu.RestaurantList = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList();
     if (objMenu.SelectedPreferences == null)
         objMenu.SelectedPreferences = new int[] { };
     return View(objMenu);
 }
 public ActionResult CreateMenu(Menu objMenu)
 {
     objMenu.PreferencesList = objContext.ContextPreferences.Where(s => s.Status == 1).ToList();
     objMenu.RestaurantList = objContext.ContextRestaurant.Where(s => s.Status == 1).ToList();
     if (objMenu.SelectedPreferences == null)
         objMenu.SelectedPreferences = new int[] { };
     if (string.IsNullOrEmpty(objMenu.Name))
     {
         ModelState.AddModelError("Name", "Please enter the Name");
     }
     if (string.IsNullOrEmpty(objMenu.Type))
     {
         ModelState.AddModelError("Type", "Please enter type");
     }
     if (objMenu.Restaurant.Id <= 0)
     {
          ModelState.AddModelError("Restaurant", "Please select restaurant");
     }
     if (ModelState.Values.SelectMany(s => s.Errors).Count() > 0)
     {
         return View(objMenu);
     }
     try
     {
         objMenu.Restaurant = objContext.ContextRestaurant.Find(objMenu.Restaurant.Id);
         objMenu.MenuPreferencesList = new List<MenuPreferences>();
         MenuPreferences objMenuPreferences;
         foreach (int id in objMenu.SelectedPreferences)
         {
             objMenuPreferences = new MenuPreferences();
             objMenuPreferences.Preferences = objContext.ContextPreferences.Find(id);
             objMenu.MenuPreferencesList.Add(objMenuPreferences);
         }
         objMenu.CreatedDtm = DateTime.Now;
         objMenu.Status = 1;
         objContext.ContextMenu.Add(objMenu);
         objContext.SaveChanges();
         return RedirectToAction("ListMenu");
     }
     catch
     {
     }
     TempData.Remove("Message");
     TempData.Add("Message", "Menu creation failed");
     
     return View(objMenu);
 }