Ejemplo n.º 1
0
        public ActionResult ProductDetails(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var prod = manager.GetProductById(id.Value);

            if (prod == null)
            {
                return(HttpNotFound());
            }
            string[] temp = prod.Images.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            ProductStoreViewModel product = new ProductStoreViewModel
            {
                Name             = prod.Name,
                Price            = prod.Price,
                ShortDescription = prod.Description,
                LongDescription  = prod.LongDescription,
                ProductID        = prod.Id,


                Images = (from t in temp
                          select Url.Content(ConfigurationManager.AppSettings["picPath"]
                                             .ToString() + "/Product/" + t)).ToList()
            };

            return(View(product));
        }
Ejemplo n.º 2
0
        public ActionResult <ProductShowViewModel> Store([FromBody] ProductStoreViewModel viewModel)
        {
            var product = _mapper.Map <Product>(viewModel);

            _productRepository.Add(product);

            _uow.Commit();

            return(CreatedAtAction(nameof(Show), new { id = product.Id }, _mapper.Map <ProductShowViewModel>(product)));
        }