Ejemplo n.º 1
0
        public ActionResult Detail(int id)
        {
            int top          = int.Parse(ConfigHelper.GetByKey("Top"));
            var productModel = _productService.GetById(id);

            _productService.IncreaseView(productModel.ID);
            _productService.Update(productModel);
            _productService.Save();
            var viewModel      = Mapper.Map <Product, ProductViewModel>(productModel);
            var image          = _productImageService.GetAll(id);
            var imageVm        = Mapper.Map <IEnumerable <ProductImage>, IEnumerable <ProductImageViewModel> >(image);
            var listSizeColor  = _productQuantityService.GetListByProduct(id);
            var relatedProduct = _productService.GetReatedProducts(id, top);

            ViewBag.RelatedProducts = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(relatedProduct);
            ViewBag.MoreImages      = imageVm;
            var tag = _productService.GetListTagByProductId(id);

            ViewBag.Tags = Mapper.Map <IEnumerable <Tag>, IEnumerable <TagViewModel> >(tag);
            ViewBag.Size = listSizeColor;
            int total = _commentService.CountProduct(id);

            if (Request.IsAuthenticated)
            {
                var userId     = User.Identity.GetUserId();
                var userNameId = User.Identity.GetUserName();
                ViewBag.UserId     = userId;
                ViewBag.UserNameId = userNameId;
                ViewBag.TotalCount = total;
            }
            return(View(viewModel));
        }