public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }

            Product product = _productService.GetProductById(id.GetValueOrDefault());

            if (product == null)
            {
                return(View("Error"));
            }

            var cartItem = _cartService.GetCartItems().SingleOrDefault(x => x.ProductId == product.Id);

            // Can also be mapped this way ---<
            //var productDetailViewModel = Mapper.Map<Product, ProductDetailViewModel>(product, opts =>
            //{
            //    opts.Items["CartItemCount"] = _cartService.GetItemCount(product.Id);
            //    opts.Items["ProductImages"] = _productImageService.GetAllImagesByProductId(product.Id);
            //    opts.Items["CartItemRecordId"] = cartItem?.RecordId ?? 0;
            //}); //------>

            var productDetailViewModel = Mapper.Map <ProductDetailViewModel>(product);

            productDetailViewModel.CartItemCount    = _cartService.GetItemCount(product.Id);
            productDetailViewModel.ProductImages    = _productImageService.GetAllImagesByProductId(product.Id);
            productDetailViewModel.CartItemRecordId = cartItem?.RecordId ?? 0;

            return(View(productDetailViewModel));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            var product = _productService.GetProductById(id.GetValueOrDefault());

            if (product == null)
            {
                return(HttpNotFound());
            }

            var productEditFormViewModel = Mapper.Map <ProductEditFormViewModel>(product);

            productEditFormViewModel.Categories    = _categoryService.GetAllCategories();
            productEditFormViewModel.ProductImages = _productImageService.GetAllImagesByProductId(id.GetValueOrDefault());

            return(View(productEditFormViewModel));
        }