public int AddAndReturnID(MealItem mealitem)
        {
            mealitem.DateCreated = DateTime.Now;
              //mealitem.Status = 1;
              //mealitem.Price =10.0M;

              unitOfWork.mealitemrepository.Add(mealitem);
              unitOfWork.Save();

              int mealitemid = mealitem.MealItemId;

               //  unitOfWork.Save();

             foreach (var photo in mealitem.MealItems_Photos)
             {
                 photo.MealItemID = mealitemid;
                 unitOfWork.MealItemPhotoRepository.Add(photo);
             }
             foreach (var aller in mealitem.MealItems_AllergenicFoods)
             {

                 aller.MealItemID = mealitemid;
                 unitOfWork.MealAllergenRepository.Add(aller);
             }
             unitOfWork.Save();
             unitOfWork.Dispose();

            return mealitemid;
        }
        public void Add(MealItem mealitem)
        {
            mealitem.DateCreated = DateTime.Now;
            //mealitem.Status = 1;
            //mealitem.Price = 10.0M;

            unitOfWork.mealitemrepository.Add(mealitem);
            unitOfWork.Save();
            unitOfWork.Dispose();
        }
        //
        // GET: /MealItem/Create
        public ActionResult Create()
        {
            MealItem mt = new MealItem();
            mt.UserId = WebSecurity.CurrentUserId;

            MealItemViewModel mtvm = Mapper.Map<MealItem, MealItemViewModel>(mt);

            mtvm = PopulateDropDown(mtvm, mt);

            return View(mtvm);
        }
        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 CreateMealItemDD(int userID)
        {
            MealItem mt = new MealItem();
            mt.UserId = userID;

            MealItemViewModel mtvm = Mapper.Map<MealItem, MealItemViewModel>(mt);

            mtvm = PopulateDropDown(mtvm, mt);

            return Json(mtvm, JsonRequestBehavior.AllowGet);
        }
        //
        // 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);
            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(mealitem);
        }
 public void Delete(MealItem mt)
 {
     throw new NotImplementedException();
 }
 public void Update(MealItem mt)
 {
     unitOfWork.mealitemrepository.Update(mt);
     unitOfWork.Save();
     unitOfWork.Dispose();
     //unitOfWork.Save();
     //unitOfWork.Dispose();
     //throw new NotImplementedException();
 }