private MealItemViewModel PopulateDropDown(MealItemViewModel mtvm, MealItem mealitem)
        {
            IMealItemService _service = new MealItemService();
            if (mtvm == null)
                mtvm = new MealItemViewModel();
            mtvm.ServingUnitDDList = _service.GetServingUnitDDList().Select(x => new SelectListItem
            {
                Value = x.ServingUnitID.ToString(),
                Text = x.ServingUnit,
                Selected = (mealitem != null && mealitem.ServingUnit == x.ServingUnitID)
            });

            mtvm.MealTypeDD.MealTypeDDList = _service.MealTypeDDList().Select(x => new SelectListItem
            {
                Value = x.MealTypeID.ToString(),
                Text = x.Name,
                Selected = (mealitem != null && mealitem.MealTypeID == x.MealTypeID)
            });
            mtvm.CusineTypeDD.CuisineDDList = _service.CuisineTypeDDList().Select(x => new SelectListItem
            {
                Value = x.CuisineTypeID.ToString(),
                Text = x.Name,
                Selected = (mealitem != null && mealitem.CusineTypeID == x.CuisineTypeID)
            });

            mtvm.DietTypeDD.DietTypeDDList = _service.DietTypeDDList().Select(x => new SelectListItem
            {
                Value = x.DietTypeID.ToString(),
                Text = x.Name,
                Selected = (mealitem != null && mealitem.DietTypeID == x.DietTypeID)
            });
            mtvm.AllergenDD = _service.AllergenicFoodsDDList().Select(x => new Allergen
            {
                AllergenName = x.AllergenicFood,
                AllergenID = x.AllergenicFoodID,
                Selected = (mealitem != null && mealitem.MealItems_AllergenicFoods.Where(y => y.AllergenicFoodID == x.AllergenicFoodID).Count() > 0)
            }).ToList();

            return mtvm;
        }
        public JsonResult MyMealItem(int userID)
        {
            IMealItemService _service = new MealItemService();
            IEnumerable<MealItem> mt = _service.FindByUser(userID);
            IEnumerable<MealItemViewModel> mtvm = Mapper.Map<IEnumerable<MealItem>, IEnumerable<MealItemViewModel>>(mt);
            //mtvm = PopulateDropDown(mtvm);

            return Json(mtvm, JsonRequestBehavior.AllowGet);
        }
 public JsonResult SearchMealItem(string mealItemName)
 {
     if (!string.IsNullOrEmpty(mealItemName))
     {
         IMealItemService _service = new MealItemService();
         IEnumerable<MealItem> mt = _service.GetAll().Where(x => x.MealItemName.Contains(mealItemName.Trim()));
         IEnumerable<MealItemViewModel> mtvm = Mapper.Map<IEnumerable<MealItem>, IEnumerable<MealItemViewModel>>(mt);
         return Json(mtvm, JsonRequestBehavior.AllowGet);
     }
     else
     {
         return Json(new { success = false, msg = "Meal item name cannnot be empty" }, JsonRequestBehavior.AllowGet);
     }
 }
        public JsonResult CreateMealItem(MealItemViewModel mtvms)
        {
            IMealItemService _service = new MealItemService();
            MealItem mealitem = Mapper.Map<MealItemViewModel, MealItem>(mtvms);
            foreach (var mealaller in mtvms.AllergenDD)
            {
                if (mealaller.Selected)
                {
                    MealItems_AllergenicFoods aller = new MealItems_AllergenicFoods();
                    aller.AllergenicFoodID = mealaller.AllergenID;
                    mealitem.MealItems_AllergenicFoods.Add(aller);
                }
            }

            mealitem.MealItemId = _service.AddAndReturnID(mealitem);

            return Json(new { success = true, id = mealitem.MealItemId }, JsonRequestBehavior.AllowGet);
        }