/// <summary> /// TODO /// </summary> /// <param name="service"></param> /// <param name="continentId"></param> /// <param name="languageID"></param> /// <returns></returns> public async Task <(int, IEnumerable <HRCountry>)> GetHRCountriesByContinentByLanguageAsync( ICoreCountriesService service, string continentId, string languageID) { Region region; if (service == null) { return(StatusCodes.Status500InternalServerError, null); } if (!Enum.TryParse(continentId, out region) || String.IsNullOrEmpty(languageID)) { return(StatusCodes.Status400BadRequest, null); } else { try { using (Task <IEnumerable <HRCountry> > task = service.GetHRCountriesByContinentByLanguageAsync(region, languageID)) { await task; return(StatusCodes.Status200OK, task.Result); } } catch (Exception) { return(StatusCodes.Status500InternalServerError, null); } } }
/// <summary> /// Version 1 : Get HRCountry then HRBorder one by one. /// 1- Get Corresponding HRCountries to build list of ISO2 codes. /// 2- Get HRBorders for list of ISO2 /// </summary> /// <param name="continentId"></param> /// <param name="langageId"></param> /// <returns></returns> public async Task <IEnumerable <HRBorder> > GetHRBorderByContinentByLanguageAsync(Region region, string langageId) { if (_hrCountriesService == null || _bordersRepository == null) { if (_logger != null) { _logger.LogError("_hrCountriesService or _bordersRepository is null in HRCoreBordersServices"); } throw new MemberAccessException(); } //1- using (Task <IEnumerable <HRCountry> > countriesTask = _hrCountriesService.GetHRCountriesByContinentByLanguageAsync(region, langageId)) { await countriesTask; if (countriesTask.IsCompleted) { List <HRBorder> retour = new List <HRBorder>(); //!TODO add robustness and UT Dictionary <String, Region> idsAndRegions = new Dictionary <string, Region>(); //2- foreach (HRCountry iter in countriesTask.Result) { idsAndRegions.Add(iter.Alpha2Code, iter.Region); } using (Task <IEnumerable <HRBorder> > bordersTask = _bordersRepository.GetAsync(idsAndRegions.Keys)) { await bordersTask; if (bordersTask.IsCompleted) { foreach (HRBorder borderIter in bordersTask.Result) { borderIter.BorderRegion = idsAndRegions[borderIter.ISO2].ToString(); retour.Add(borderIter); } return(retour); } else { throw new Exception("GetAsync (HRBorders) fail."); } } } else { throw new Exception("GetHRBorderByContinentByLanguageAsync fail"); } } }