예제 #1
0
        public IEnumerable <StaticContent> GetBySeoUrl(string seoUrl, bool isCache = true)
        {
            var sbKey = new StringBuilder();

            sbKey.AppendFormat(CacheKey, "GetBySeoUrl");

            if (seoUrl.HasValue())
            {
                sbKey.AppendFormat("-{0}", seoUrl);
            }

            var key = sbKey.ToString();
            IEnumerable <StaticContent> staticContents;

            if (isCache)
            {
                staticContents = _cacheManager.GetCollection <StaticContent>(key);
                if (staticContents == null)
                {
                    staticContents = _staticContentRepository.FindBy(x => x.SeoUrl.Equals(seoUrl));
                    _cacheManager.Put(key, staticContents);
                }
            }
            else
            {
                staticContents = _staticContentRepository.FindBy(x => x.SeoUrl.Equals(seoUrl));
            }

            return(staticContents);
        }
예제 #2
0
        public IEnumerable <StaticContent> GetBySeoUrls(string seoUrl, int?status = null, bool isCache = true)
        {
            var expression = PredicateBuilder.True <StaticContent>();

            if (status != null)
            {
                expression = expression.And(x => x.Status == status);
            }
            if (!string.IsNullOrEmpty(seoUrl))
            {
                expression = expression.And(x => x.SeoUrl.Equals(seoUrl));
            }

            if (!isCache)
            {
                return(_staticContentRepository.FindBy(expression));
            }

            var sbKey = new StringBuilder();

            sbKey.AppendFormat(CacheKey, "GetBySeoUrls");
            sbKey.AppendFormat("-{0}", seoUrl);
            sbKey.Append(status);

            var key = sbKey.ToString();

            var staticContents = _cacheManager.GetCollection <StaticContent>(key);

            if (staticContents == null)
            {
                staticContents = _staticContentRepository.FindBy(expression);
                _cacheManager.Put(key, staticContents);
            }

            return(staticContents);
        }