コード例 #1
0
        public async Task <ActionResult> GetRecommendations(string productId)
        {
            if (!ConfigurationHelpers.GetBool("ShowRecommendations"))
            {
                return(new EmptyResult());
            }

            var recommendedProductIds = await recommendation.GetRecommendationsAsync(productId);

            var recommendedProducts = await db.Products.Where(x => recommendedProductIds.Contains(x.ProductId.ToString())).ToListAsync();

            return(PartialView("_Recommendations", recommendedProducts));
        }
コード例 #2
0
        public async Task <ActionResult> GetRecommendations(string productId)
        {
            if (!ConfigurationHelpers.GetBool("ShowRecommendations"))
            {
                return(new EmptyResult());
            }

            var recommendedProductIds = await recommendation.GetRecommendationsAsync(productId);



            return(PartialView("_Recommendations", recommendedProducts));
        }
コード例 #3
0
        public ActionResult Details(int id)
        {
            var productCacheKey = string.Format("product_{0}", id);
            var product         = MemoryCache.Default[productCacheKey] as Product;

            if (product == null)
            {
                product = db.Products.Single(a => a.ProductId == id);
                //Remove it from cache if not retrieved in last 10 minutes
                MemoryCache.Default.Add(productCacheKey, product, new CacheItemPolicy {
                    SlidingExpiration = TimeSpan.FromMinutes(10)
                });
            }
            var viewModel = new ProductViewModel
            {
                Product             = product,
                ShowRecommendations = ConfigurationHelpers.GetBool("ShowRecommendations")
            };

            return(View(viewModel));
        }