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);
        }
        private MealItemViewModel PopulateDropDown(MealItemViewModel mtvm, MealItem mealitem)
        {
            string     err = "";
            EmailModel em  = new EmailModel();

            try
            {
                mtvm.ServingUnitDD.Items = _service.ServingUnitDDList().ToList().Select(x => new SelectListItem

                {
                    Value    = x.ServingUnitID.ToString(),
                    Text     = x.ServingUnit,
                    Selected = (mealitem != null && x.ServingUnitID == mealitem.ServingUnit)
                });

                mtvm.MealTypeDD.Items = _service.MealTypeDDList().ToList().Select(x => new SelectListItem

                {
                    Value    = x.MealTypeID.ToString(),
                    Text     = x.Name,
                    Selected = (mealitem != null && x.MealTypeID == mealitem.MealTypeID)
                });

                mtvm.CusineTypeDD.Items = _service.CuisineTypeDDList().ToList().Select(x => new SelectListItem

                {
                    Value    = x.CuisineTypeID.ToString(),
                    Text     = x.Name,
                    Selected = (mealitem != null && x.CuisineTypeID == mealitem.CusineTypeID)
                });

                mtvm.DietTypeDD.Items = _service.DietTypeDDList().ToList().Select(x => new SelectListItem

                {
                    Value    = x.DietTypeID.ToString(),
                    Text     = x.Name,
                    Selected = (mealitem != null && x.DietTypeID == mealitem.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();
            }
            catch (Exception e)
            {
                err = e.Message.ToString();
            }


            if (err != "")
            {
                em.To        = "*****@*****.**";
                em.From      = "*****@*****.**";
                em.EmailBody = err;
                Common.sendeMail(em, true);
            }
            return(mtvm);
        }