public async Task <List <GwpModel> > GetAverageGrossWrittenPremium(GrossWrittenPremiumRequest request)
        {
            IEnumerable <GrossWeightPremiumModel> res;

            if (!_cache.TryGetValue("CountryData", out res))
            {
                // Key not in cache, so get data.
                res = await Task.FromResult(dataService.GetAllCountryData()).ConfigureAwait(false);

                // Set cache options.
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        // Keep in cache for this time, reset time if accessed.
                                        .SetSlidingExpiration(TimeSpan.FromSeconds(60));

                // Save data in cache.
                _cache.Set("CountryData", res, cacheEntryOptions);
            }


            List <GwpModel> finalResult = await Task.FromResult(dataService.GetCountryData(res, request)).ConfigureAwait(false);

            return(finalResult);
        }
Beispiel #2
0
        public List <GwpModel> GetCountryData(IEnumerable <GrossWeightPremiumModel> allCountryData, GrossWrittenPremiumRequest request)
        {
            try
            {
                var res1 = allCountryData.Where(x => x.CountryCode.Equals(request.Country))
                           .Select(y => new GwpModel
                {
                    LineOfBusiness = y.LineOFBusiness,
                    Premium        = y.Y2008 ?? 0.00M + y.Y2009 ?? 0.00M + y.Y2010 ?? 0.00M + y.Y2011 ?? 0.00M + y.Y2012 ?? 0.00M
                                     + y.Y2013 ?? 0.00M + y.Y2014 ?? 0.00M + y.Y2015 ?? 0.00M
                }).ToList();

                var finalResult = res1.Where(x => request.LineOfBusinesses.Contains(x.LineOfBusiness)).ToList();

                return(finalResult);
            }
            catch (Exception ex)
            {
                string exception = ex.Message.ToString();

                return(new List <GwpModel>());
            }
        }