public IActionResult AddToShoppingCart(int id) { var selectedProduct = _productsRepo.GetProductById(id); if (selectedProduct != null) { _shoppingCart.AddToCart(selectedProduct, 1); } return(RedirectToAction("Index")); }
public ActionResult <ProductReadDto> GetProductById(int id) { var product = _repository.GetProductById(id); if (product == null) { return(StatusCode(StatusCodes.Status404NotFound, $"{id} not Found")); } return(Ok(_mapper.Map <ProductReadDto>(product))); }
public IActionResult Details(int id) { Product bike = null; try { bike = _productsRepo.GetProductById(id); } catch (ArgumentException) { return(View("StatusCodes/BikeNotFound", id)); } var bikeCard = _mapper.Map <BikeCardViewModel>(bike); return(View(bikeCard)); }