Ejemplo n.º 1
0
        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)));
        }
Ejemplo n.º 3
0
        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));
        }