Ejemplo n.º 1
0
        public ViewModels.MealForListVm GetMeal(int mealId)
        {
            var meal   = _mealRepo.GetMeal(mealId);
            var mealVm = _mapper.Map <ViewModels.MealForListVm>(meal);

            mealVm.Items = new List <ItemInMealDetailVm>();
            var itemsInMeal = _itemInMealService.GetAllItemsInMeal(mealVm.Id);

            foreach (var e in itemsInMeal)
            {
                var item = _itemService.GetItemById(e.ItemId);
                var itemInMealDetailVm = CreateItemInMealDetailVm(item, itemsInMeal);
                mealVm.Items.Add(itemInMealDetailVm);
            }
            return(mealVm);
        }
Ejemplo n.º 2
0
        public IActionResult AddItemToMeal(AddItemToMealVm model)
        {
            var itemsInMeal = _itemInMealService.GetAllItemsInMeal(model.MealId);

            if (!itemsInMeal.Contains(itemsInMeal.FirstOrDefault(i => i.ItemId == model.ItemId)))
            {
                var id = _itemInMealService.AddItemToMeal(model);
                TempData["Success"] = "Item has been added to meal!";
                return(RedirectToAction("AddItemToMeal", "ItemInMeal", id = model.MealId));
                //return RedirectToAction("AddItemToMeal", "ItemInMeal", id = model.MealId);
            }
            else
            {
                TempData["Error"] = "You have arleady added this product to choosen meal!";
                return(RedirectToAction(controllerName: "ItemInMeal", actionName: "AddItemToMeal"));
            }
        }