// // GET: /MealItem/Details/5 public ActionResult Details(int id) { MealItem mealitem = _service.GetById(id); if (mealitem == null) { mealitem = new MealItem(); } MealItemViewModel mtvm = Mapper.Map <MealItem, MealItemViewModel>(mealitem); List <MealItemsPhoto> phl = new List <MealItemsPhoto>(); foreach (var p in mealitem.MealItems_Photos) { MealItemsPhoto ph = new MealItemsPhoto(); ph = Mapper.Map <MealItems_Photos, MealItemsPhoto>(p); phl.Add(ph); } mtvm.Images = phl; if (mealitem.ServingUnit != null) { mtvm.ServingUnitDD.SelectedId = _service.ServingUnitDDList().ToList().Where(x => x.ServingUnitID == mealitem.ServingUnit).FirstOrDefault().ServingUnit; } if (mealitem.MealTypeID != null) { mtvm.MealTypeDD.SelectedId = _service.MealTypeDDList().ToList().Where(x => x.MealTypeID == mealitem.MealTypeID).FirstOrDefault().Name; } if (mealitem.CusineTypeID != null) { mtvm.CusineTypeDD.SelectedId = _service.CuisineTypeDDList().ToList().Where(x => x.CuisineTypeID == mealitem.CusineTypeID).FirstOrDefault().Name; } if (mealitem.DietTypeID != null) { mtvm.DietTypeDD.SelectedId = _service.DietTypeDDList().ToList().Where(x => x.DietTypeID == mealitem.DietTypeID).FirstOrDefault().Name; } ; mtvm = PopulateDropDown(mtvm, mealitem); ViewData["MealItemViewModel"] = mtvm; //MealItemViewModel mtvm = Mapper.Map<MealItem, MealItemViewModel>(mealitem); //if (mtvm.MealTypeDD == null) // mtvm.MealTypeDD = new MealTypeDDListViewModel(); //mtvm.MealTypeDD.SelectedMealType = _service.MealTypeDDList().Where(x=>x.MealTypeID==mtvm.MealTypeDD.; return(View(mtvm)); }
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); }