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)); }
public HttpResponseMessage GetAll(HttpRequestMessage request, int productId) { return(CreateHttpResponse(request, () => { IEnumerable <ProductImage> productImageDb = _productImageService.GetAll(productId); IEnumerable <ProductImageViewModel> productImageVm = Mapper.Map <IEnumerable <ProductImageViewModel> >(productImageDb); return request.CreateResponse(HttpStatusCode.OK, productImageVm); })); }
public IActionResult GetAll() { var result = _productImageService.GetAll(); if (result.Success) { return(Ok(result)); } return(BadRequest(result)); }
public HttpResponseMessage GetAll(HttpRequestMessage request, int productId) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; var model = _productImageService.GetAll(productId); var modelVm = Mapper.Map <IEnumerable <ProductImage>, IEnumerable <ProductImageViewModel> >(model); response = request.CreateResponse(HttpStatusCode.OK, modelVm); return response; })); }
// [Permission(Action = ActionName.CanRead)] public IHttpActionResult GetAllImages(int id) { return(CreateResponse(() => { var model = _productImageService.GetAll(id); var viewModel = Mapper.Map <IEnumerable <ProductImageDto> >(model); return Ok(viewModel); })); }
// GET: Product public ActionResult Detail(int productID) { var productModel = _productService.GetById(productID); var viewModel = Mapper.Map <Product, ProductViewModel>(productModel); var relatedProduct = _productService.GetReatedProducts(productID, 8); ViewBag.RelatedProducts = Mapper.Map <IEnumerable <Product>, IEnumerable <ProductViewModel> >(relatedProduct); var model = _productImageService.GetAll(productID); ViewBag.MoreImages = Mapper.Map <IEnumerable <ProductImage>, IEnumerable <ProductImageViewModel> >(model); ViewBag.Tags = Mapper.Map <IEnumerable <Tag>, IEnumerable <TagViewModel> >(_productService.GetListTagByProductId(productID)); return(View(viewModel)); }
public ActionResult Details(int id) { var product = _productService.GetById(id); if (product == null) { return(HttpNotFound()); } var productDetail = new ProductDetailViewModel { Product = Mapper.Map <ProductViewModel>(product), Images = Mapper.Map <IEnumerable <ProductImageViewModel> >(_productImageService.GetAll(id)), }; return(View(productDetail)); }
public HttpResponseMessage UpdateThumbnail(HttpRequestMessage request, int productId) { return(CreateHttpResponse(request, () => { try { ProductImage ProductImage = _productImageService.GetAll(productId).FirstOrDefault(); Product productDb = _productService.GetById(productId); productDb.ThumbnailImage = ProductImage.Path; _productService.Update(productDb); _productService.SaveChanges(); return request.CreateResponse(HttpStatusCode.Created, productId); } catch { return request.CreateErrorResponse(HttpStatusCode.BadRequest, "Sản phẩm không có ảnh"); } })); }