public ActionResult Detail(int productId) { var product = _productService.GetProductById(productId); if (product == null) { return(Redirect("/")); } var model = product.MapTo <ProductModel>(); var images = _imageService.GetProductImagesByProductId(productId); model.SubPictures = images.Select(i => new ProductModel.ProductPictureModel { Id = i.Id, IsDefault = i.Url == product.ProductImage, PictureUrl = i.Url, ProductId = i.ProductId }).ToList(); var brand = _brandService.GetBrandById(model.BrandId); if (brand != null) { var brandToProductCount = _cacheManager.GetCache(Products.CACHE_PRODUCT_TO_BRAND_COUNT).Get(brand.Id.ToString(), () => { var products = _productService.GetAllProducts(brand: brand.Id); return(products.TotalCount); }); model.BrandName = brand.Name; model.BrandImage = brand.BrandImage; model.BrandToProductCount = brandToProductCount; } //属性 PrepareProductAttribute(model); //关联商品 PrepareProductRelated(model); //收藏 if (CustomerId == 0) { model.IsFavorites = false; } else { var favorites = _favoriteService.GetAllFavorites(customerId: this.CustomerId); model.IsFavorites = favorites.Items.FirstOrDefault(f => f.ProductId == productId) != null; } if (model.AllowReward) { var rate = _settingService.GetSettingByKey <int>(RewardSettingNames.PaymentRate); model.RewardExchange = Convert.ToInt32(model.Price * rate); } ViewData["CustomerId"] = AbpSession.UserId; return(View(model)); }
protected void PrepareProductImagesModel(ProductModel model) { if (model == null) { throw new UserFriendlyException("model"); } var images = _productImageService.GetProductImagesByProductId(model.Id); foreach (var item in images) { model.AvailablePictures.Add(new ProductModel.ProductPictureModel { Id = item.Id, PictureUrl = item.Url, ProductId = item.ProductId }); } }