Example #1
0
        private MealItemViewModel PopulateDropDown(MealItemViewModel mtvm)
        {
            mtvm.ServingUnitDDList = _service.GetServingUnitDDList().Select(x => new SelectListItem
            {
                Value = x.ServingUnitID.ToString(),
                Text  = x.ServingUnit
            });



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

            mtvm.DietTypeDD.DietTypeDDList = _service.DietTypeDDList().Select(x => new SelectListItem
            {
                Value = x.DietTypeID.ToString(),
                Text  = x.Name
            });
            mtvm.AllergenDD = _service.AllergenicFoodsDDList().Select(x => new Allergen
            {
                AllergenName = x.AllergenicFood.ToString(),
                AllergenID   = x.AllergenicFoodID,
                Selected     = false
            }).ToList();
            return(mtvm);
        }
        private MealItemViewModel PopulateDropDown(MealItemViewModel mtvm, MealItem mealitem)
        {
            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);
        }