public IActionResult Add(int id, int?amount = 1)
        {
            var food = _foodService.GetById(id);

            bool isValidAmount = false;

            if (food != null)
            {
                isValidAmount = _shoppingCart.AddToCart(food, amount.Value);
            }

            return(Index(isValidAmount));
        }
Exemple #2
0
        public IActionResult Add(int id, int?amount = 1, string returnUrl = null)
        {
            var food = _foodService.GetById(id);

            returnUrl = returnUrl.Replace("%2F", "/");
            bool isValidAmount = false;

            if (food != null)
            {
                isValidAmount = _shoppingCart.AddToCart(food, amount.Value);
            }

            return(Index(isValidAmount, returnUrl));
        }
Exemple #3
0
        public IActionResult Index(int id)
        {
            var food = _foodService.GetById(id);

            var model = new FoodIndexModel
            {
                Id           = food.Id,
                Name         = food.Name,
                ImageUrl     = food.ImageUrl,
                InStock      = food.InStock,
                Price        = food.Price,
                Description  = food.ShortDescription + "\n" + food.LongDescription,
                CategoryId   = food.Category.Id,
                CategoryName = food.Category.Name
            };

            return(View(model));
        }
Exemple #4
0
        public IActionResult AddToCart(int id)
        {
            var food = _food.GetById(id);

            if (food != null)
            {
                _cart.AddToCart(food, 1);
            }

            return(RedirectToAction("Index"));
        }
Exemple #5
0
        // GET: FoodController/Details/5
        public ActionResult Details(int id)
        {
            var model = _food.GetById(id);

            return(View(model));
        }