Exemplo n.º 1
0
        public async Task <IActionResult> Index(string slug)
        {
            if (string.IsNullOrWhiteSpace(slug))
            {
                return(BadRequest());
            }

            var cacheKey     = $"page-{slug.ToLower()}";
            var pageResponse = await _cache.GetOrCreateAsync(cacheKey, async entry =>
            {
                entry.SlidingExpiration = TimeSpan.FromMinutes(AppSettings.CacheSlidingExpirationMinutes["Page"]);

                var response = await _customPageService.GetAsync(slug);
                return(response);
            });

            if (pageResponse.IsSuccess)
            {
                if (pageResponse.Item == null)
                {
                    Logger.LogWarning($"Page not found. {nameof(slug)}: '{slug}'");
                    return(NotFound());
                }

                if (!pageResponse.Item.IsPublished)
                {
                    return(NotFound());
                }

                return(View(pageResponse.Item));
            }
            return(ServerError());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Index(string slug)
        {
            if (string.IsNullOrWhiteSpace(slug))
            {
                return(BadRequest());
            }

            var page = await _cache.GetOrCreateAsync(CacheDivision.Page, slug.ToLower(), async entry =>
            {
                entry.SlidingExpiration = TimeSpan.FromMinutes(AppSettings.CacheSlidingExpirationMinutes["Page"]);

                var p = await _customPageService.GetAsync(slug);
                return(p);
            });

            if (page == null)
            {
                Logger.LogWarning($"Page not found. {nameof(slug)}: '{slug}'");
                return(NotFound());
            }

            if (!page.IsPublished)
            {
                return(NotFound());
            }

            return(View(page));
        }