public IActionResult GetPostalCodesForCountry(int countryId) { if (!_repository.CountryExists(countryId)) { return(NotFound()); } var postalCodesForCountryFromRepo = _repository.GetPostalCodesForCountry(countryId); var postalCodesForCountry = Mapper.Map <IEnumerable <Models.AreaPostalCodeDto> >(postalCodesForCountryFromRepo); postalCodesForCountry = postalCodesForCountry.Select(postalCode => { postalCode = CreateLinksForPostalCode(postalCode); return(postalCode); }); var wrapper = new LinkedCollectionResourceWrapperDto <AreaPostalCodeDto>(postalCodesForCountry); return(Ok(CreateLinksForPostalCodes(wrapper))); }
public IActionResult Get(int countryId) { try { var countryExists = _countryInfoRepository.CountryExists(countryId); if (!countryExists) { _logger.LogInformation($"country with id {countryId} wasn't found on endpoint Languagues/Get"); return(NotFound()); } var languagues = _countryInfoRepository.GetOfficialLanguages(countryId); if (languagues == null) { return(NotFound()); } var languaguesResults = new List <OfficialLanguagesByCountryDTO>(); foreach (var lang in languagues) { languaguesResults.Add(new OfficialLanguagesByCountryDTO() { Id = lang.Id, LanguageName = lang.LanguageName }); } return(Ok(languaguesResults)); } catch (Exception e) { _logger.LogInformation($"country with id {countryId} did a exception {e.Message} on endpoint Languagues/Get "); return(StatusCode(500, "A problem happened while handling your request.")); } }