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)); }
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)); }
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)); }
public IActionResult AddToCart(int id) { var food = _food.GetById(id); if (food != null) { _cart.AddToCart(food, 1); } return(RedirectToAction("Index")); }
// GET: FoodController/Details/5 public ActionResult Details(int id) { var model = _food.GetById(id); return(View(model)); }