Пример #1
0
        public async Task <ActionResult> Get(int id, [FromQuery] int[] serviceIds, string homeRegion, string state = ElasticIndex.DefaultState, string language = ElasticIndex.DefaultLanguage, bool html = false)
        {
            var searchOptions = new SearchOptions()
            {
                BaseUrls   = ConfigurationOptions.ElasticUrls,
                IndexName  = ConfigurationOptions.GetIndexName(state, language),
                HomeRegion = homeRegion
            };

            ConfigureOptions(searchOptions);

            var cacheKey = GetCacheKey(GetType().ToString(), id, serviceIds, homeRegion, homeRegion, state, language);
            var result   = await GetCachedResult(cacheKey, searchOptions, html);

            if (result != null)
            {
                return(result);
            }

            result = await FillHomeRegion(searchOptions);

            result = result ?? await LoadProducts(id, serviceIds, searchOptions);

            result = result ?? await FillDefaultHomeRegion(searchOptions, Product);

            if (ConfigurationOptions.LoadDefaultServices && Services != null && !Services.Any())
            {
                result = result ?? await LoadDefaultService(searchOptions);
            }

            result = result ?? FilterServicesOnProduct(true);

            LogStartImpact("Base", id, serviceIds);

            result = result ?? CalculateImpact(searchOptions.HomeRegionData);

            LogEndImpact("Base", id, serviceIds);

            result = result ?? (html ? TestLayout(Product, serviceIds, state, language, homeRegion) : Content(Product.ToString()));

            if (!IsCacheDisabled(html))
            {
                SetCachedResult(id, serviceIds, result, cacheKey);
            }

            return(result);
        }