Ejemplo n.º 1
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            int shortCacheTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["shortCacheTime"]);

            int    StoreID  = CommonConfig.StoreID;
            string TokenKey = CommonConfig.TokenKey;

            WebService.ProductItem[]        saleProduct;
            WebService.SearchResult         bestSaleProduct;
            WebService.SearchArticleResults topArticle;
            WebService.Webconfig            webConfig;

            WebService.AnperoService sv = new WebService.AnperoService();

            Anpero.ICacheService cache = new Anpero.CacheService();

            if (!cache.TryGet(BaseController.SaleProductCache, out saleProduct))
            {
                saleProduct = sv.GetSaleProduct(StoreID, TokenKey);
                cache.AddOrUpdate(BaseController.SaleProductCache, saleProduct, DateTime.Now.AddMinutes(shortCacheTime));
            }

            if (!cache.TryGet(BaseController.BestSaleProductCache, out bestSaleProduct))
            {
                bestSaleProduct = sv.SearchProductFullData(StoreID, TokenKey, "0", "0", "0", 0, 99999999, 1, 7, "", SearchOrder.TimeDesc, 1, true);
                cache.AddOrUpdate(BaseController.BestSaleProductCache, bestSaleProduct, DateTime.Now.AddMinutes(shortCacheTime));
            }

            if (!cache.TryGet(BaseController.TopArticleCache, out topArticle))
            {
                topArticle = sv.SearchArticle(StoreID, TokenKey, 0, 1, 4, 2);
                cache.AddOrUpdate(BaseController.TopArticleCache, topArticle, DateTime.Now.AddMinutes(shortCacheTime));
            }

            if (!cache.TryGet(BaseController.CommonInfoCache, out webConfig))
            {
                webConfig = sv.GetCommonConfig(CommonConfig.StoreID, CommonConfig.TokenKey);
                cache.AddOrUpdate(BaseController.CommonInfoCache, webConfig, DateTime.Now.AddMinutes(shortCacheTime));
            }

            filterContext.Controller.ViewData["saleProduct"]     = saleProduct;
            filterContext.Controller.ViewData["BestsaleProduct"] = bestSaleProduct;
            filterContext.Controller.ViewData["FeatureArticle"]  = topArticle;
            filterContext.Controller.ViewData["commonInfo"]      = webConfig;
        }
Ejemplo n.º 2
0
        private void SetUpSlideAds()
        {
            int shortCacheTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["shortCacheTime"]);

            WebService.AnperoService service = new WebService.AnperoService();

            WebService.Ads[] Slide;
            WebService.Ads[] ads1;
            WebService.Ads[] ads2;
            //WebService.Ads[] ads3;

            Anpero.ICacheService cache = new Anpero.CacheService();

            if (!cache.TryGet(SlideCache, out Slide))
            {
                Slide = service.GetAdsSlide(StoreID, TokenKey, PageContent.Slide);
                cache.AddOrUpdate(SlideCache, Slide, DateTime.Now.AddMinutes(shortCacheTime));
            }

            if (!cache.TryGet(Ads1Cache, out ads1))
            {
                ads1 = service.GetAdsSlide(StoreID, TokenKey, PageContent.Ads1);
                cache.AddOrUpdate(Ads1Cache, ads1, DateTime.Now.AddMinutes(shortCacheTime));
            }

            if (!cache.TryGet(Ads2Cache, out ads2))
            {
                ads2 = service.GetAdsSlide(StoreID, TokenKey, PageContent.Ads2);
                cache.AddOrUpdate(Ads2Cache, ads2, DateTime.Now.AddMinutes(shortCacheTime));
            }

            //if (!cache.TryGet(Ads3Cache, out ads3))
            //{
            //    ads3 = service.GetAdsSlide(StoreID, TokenKey, PageContent.Ads3);
            //    cache.AddOrUpdate(Ads3Cache, ads3, DateTime.Now.AddMinutes(shortCacheTime));
            //}
            ViewBag.Slide = Slide;
            ViewBag.Ads1  = ads1;
            ViewBag.Ads2  = ads2;
            // ViewBag.Ads3 = ads3;

            Response.Cache.SetCacheability(HttpCacheability.Public);
        }
Ejemplo n.º 3
0
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            WebService.AnperoService service      = new WebService.AnperoService();
            Anpero.ICacheService     cacheService = new Anpero.CacheService();
            Webconfig config = new Webconfig();

            WebService.Ads[] Slide    = null;
            WebService.Ads[] AdsSlide = null;
            WebService.SearchArticleResults FeatureArticle = new WebService.SearchArticleResults();
            int shortCacheTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["shortCacheTime"]);

            if (!cacheService.TryGet("commonInfo", out config))
            {
                config = service.GetCommonConfig(CommonConfig.StoreID, CommonConfig.TokenKey);
                cacheService.AddOrUpdate("commonInfo", config, new TimeSpan(0, 6, 0));
            }
            if (!cacheService.TryGet("Slide", out Slide))
            {
                Slide = service.GetRandomAdsSlide(CommonConfig.StoreID, CommonConfig.TokenKey, PageContent.Slide, 1);
                cacheService.AddOrUpdate("Slide", Slide, new TimeSpan(0, 6, 0));
            }
            if (!cacheService.TryGet("AdsSlide", out AdsSlide))
            {
                AdsSlide = service.GetAdsSlide(CommonConfig.StoreID, CommonConfig.TokenKey, PageContent.Ads1);
                cacheService.AddOrUpdate("AdsSlide", AdsSlide, new TimeSpan(0, 6, 0));
            }
            if (!cacheService.TryGet("FeatureArticle", out FeatureArticle))
            {
                FeatureArticle = service.SearchArticle(CommonConfig.StoreID, CommonConfig.TokenKey, 0, 1, 5, 1);
                cacheService.AddOrUpdate("FeatureArticle", FeatureArticle, new TimeSpan(0, 6, 0));
            }


            filterContext.Controller.ViewData["slide"]          = Slide;
            filterContext.Controller.ViewData["FeatureArticle"] = FeatureArticle;
            filterContext.Controller.ViewData["AdsSlide"]       = AdsSlide;
            filterContext.Controller.ViewData["commonInfo"]     = config;
        }
Ejemplo n.º 4
0
        private void GetNewestProduct()
        {
            WebService.AnperoService service      = new WebService.AnperoService();
            WebService.SearchResult  searchResult = new WebService.SearchResult();
            int shortCacheTime = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["shortCacheTime"]);

            Anpero.ICacheService cache = new Anpero.CacheService();

            if (!cache.TryGet(NewestProductCache, out searchResult))
            {
                searchResult = service.SearchProduct(StoreID, TokenKey, "", "", "", 0, int.MaxValue, 1, 7, "", SearchOrder.TimeDesc, 0, string.Empty);
                cache.AddOrUpdate(NewestProductCache, searchResult, DateTime.Now.AddMinutes(shortCacheTime));
            }

            ViewData["newestProduct"] = searchResult;
        }
Ejemplo n.º 5
0
 public ActionResult Index()
 {
     GetNewestProduct();
     SetupCommonProduct();
     SetUpSlideAds();
     WebService.SearchResult  featureleProduct;
     WebService.AnperoService sv    = new WebService.AnperoService();
     Anpero.ICacheService     cache = new Anpero.CacheService();
     if (!cache.TryGet("featureleProduct", out featureleProduct))
     {
         featureleProduct = sv.SearchProduct(StoreID, TokenKey, "", "", "", 0, 1999999990, 1, 8, "", SearchOrder.TimeDesc, 2, string.Empty);
         if (featureleProduct != null)
         {
             cache.AddOrUpdate("featureleProduct", featureleProduct, new TimeSpan(0, 10, 0));
         }
     }
     ViewData["featureleProduct"] = featureleProduct;
     return(View());
 }
Ejemplo n.º 6
0
        private void SetUpSeo(int type, int categoryId)
        {
            AnperoFrontend.WebService.Webconfig commonInfo;
            Anpero.ICacheService cache = new Anpero.CacheService();

            if (!cache.TryGet(CommonInfoCache, out commonInfo))
            {
                var service = new WebService.AnperoService();
                commonInfo = service.GetCommonConfig(CommonConfig.StoreID, CommonConfig.TokenKey);

                cache.AddOrUpdate(CommonInfoCache, commonInfo, DateTime.Now.AddMinutes(shortCacheTime));
            }

            ViewData["commonInfo"] = commonInfo;
            //Get Description and Keywords of Category production
            ViewBag.Description = string.Empty;
            ViewBag.Keywords    = string.Empty;
            ViewBag.WebsiteUrl  = string.Empty;
            ViewBag.ImageUrl    = string.Empty;
            string title = ViewBag.Title;

            if (commonInfo != null)
            {
                if (string.IsNullOrEmpty(title))
                {
                    ViewBag.Title = "Tìm kiếm trên " + commonInfo.Name;
                }

                switch (type)
                {
                case 1:
                    foreach (var item in commonInfo.ProductCategoryList)
                    {
                        if (item.Id == categoryId)
                        {
                            ViewBag.Keywords    = item.Keywords;
                            ViewBag.Description = item.Description;
                            ViewBag.WebsiteUrl  = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + Anpero.StringHelpper.GetParentCategoryLink(item.Name, item.Id);
                            ViewBag.Title       = item.Name;
                            ViewBag.ImageUrl    = item.Images;
                            break;
                        }
                    }
                    break;

                case 2:
                    foreach (var item in commonInfo.ProductCategoryList)
                    {
                        foreach (var chidItem in item.ChildCategory)
                        {
                            if (chidItem.Id == categoryId)
                            {
                                ViewBag.Keywords    = item.Keywords;
                                ViewBag.Description = item.Description;
                                ViewBag.WebsiteUrl  = Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host + Anpero.StringHelpper.GetCategoryLink(chidItem.Name, chidItem.Id);
                                ViewBag.Title       = item.Name;
                                ViewBag.ImageUrl    = item.Images;
                                break;
                            }
                        }
                    }
                    break;

                default:
                    ViewBag.Keywords    = "Tìm kiếm " + commonInfo.Name + "| " + commonInfo.Desc;
                    ViewBag.Description = "Tìm kiếm trên " + commonInfo.Name + "| " + commonInfo.Desc;
                    ViewBag.WebsiteUrl  = Request.Url.AbsoluteUri;
                    ViewBag.Title       = "";
                    ViewBag.ImageUrl    = commonInfo.Logo;
                    break;
                }
            }
        }