public CountryResult GetCountryName(string isoCode) { var result = new CountryResult(); var isoCodeUpperCase = ConvertToUpperCase(isoCode); var countryKvp = ConvertJsonToKvp(_jsonString); if (IsValidCode(isoCodeUpperCase, countryKvp)) { result.CountryName = GetName(isoCodeUpperCase, countryKvp); result.Status = CountryStatus.Valid; result.HttpStatusCode = HttpStatusCode.OK; } else { result.Status = CountryStatus.Invalid; result.HttpStatusCode = HttpStatusCode.NotFound; } return(result); }
public async Task <CountryResult> GetCountriesByIdsAsync(List <int> countryIds, int defaultLanguageId, List <int> localeLanguageIdList, List <ImageDTO> imagesFromCache) { var countryList = new CountryResult(); if (imagesFromCache == null || imagesFromCache.Count == 0) { imagesFromCache = await _imageCacheService.GetAllAsync("imagesCacheKey"); } // Fetch the data from Cache var countriesFromCache = await _countryCacheService.GetAllAsync("countriesCacheKey"); var countries = countriesFromCache.Where(co => localeLanguageIdList.Contains(co.LanguageId) && countryIds.Contains(co.Uuid)).ToList(); if (countries == null || countries.Count == 0) { countries = countriesFromCache.Where(c => c.LanguageId.Equals(defaultLanguageId) && countryIds.Contains(c.Uuid)).ToList(); if (countries.Count == 0) { return(null); } } countryList.Countries.AddRange(countries.Select(co => new CountryDTO { Uuid = co.Uuid, PNGImagePath = imagesFromCache.FirstOrDefault(im => im.ImageId.Equals(co.PNGImageId)).FilePath, SVGImagePath = imagesFromCache.FirstOrDefault(im => im.ImageId.Equals(co.SVGImageId)).FilePath, DisplayName = co.DisplayName, DisplayNameShort = co.DisplayName, Name = Helper.ReplaceChars(co.DisplayName), Path = Helper.ReplaceChars(co.DisplayName), CompleteResponse = true })); return(countryList); }
private async Task <CountryResult> GetAllCountriesDataAsync(int languageId) { var countryList = new CountryResult(); var images = await _imageCacheService.GetAllAsync("imagesCacheKey"); //var countries = await _dbContext.Countries.Where(cc => cc.IsPublished.Equals(true) && cc.LanguageId.Equals(languageId)) // .Select(c => new { c.CountryId, c.DisplayName, c.PNGImageId, c.SVGImageId, }) // .Skip((pageNo - 1) * 100).Take(pageSize).AsNoTracking().ToListAsync(); ////var countries = await _dbContext.Countries.Where(cc => cc.IsPublished.Equals(true)) //// .Select(c => new { c.CountryId, c.DisplayName, c.PNGImageId, c.SVGImageId, c.LanguageId }) //// .OrderByDescending(s => s.CountryId) //// .Skip((pageNo - 1) * 100).Take(pageSize).AsNoTracking().ToListAsync(); ////countries = countries.Where(s => s.LanguageId.Equals(languageId)).ToList(); // Fetch the data from Cache var countriesFromCache = await _countryCacheService.GetAllAsync("countriesCacheKey"); var countries = countriesFromCache.Where(c => c.LanguageId.Equals(languageId)).ToList(); if (countries.Count == 0) { return(null); } countryList.Countries.AddRange(countries.Select(co => new CountryDTO { Uuid = co.Uuid, PNGImagePath = images.FirstOrDefault(im => im.ImageId.Equals(co.PNGImageId)).FilePath, SVGImagePath = images.FirstOrDefault(im => im.ImageId.Equals(co.SVGImageId)).FilePath, DisplayName = co.DisplayName, DisplayNameShort = co.DisplayName, Name = Helper.ReplaceChars(co.DisplayName), Path = Helper.ReplaceChars(co.DisplayName), CompleteResponse = true })); return(countryList); }