public dynamic GetActiveCountries() { try { CountryRepository countryRepository = new CountryRepository(); var countriesList = countryRepository.GetActiveCountries(); if (countriesList != null) { Logger.Instance.WriteInLog(LogType.INFO, "Countries successfully obtained"); CountryResponse countryResponse = new CountryResponse(); countryResponse.countries = new List <Country>(); foreach (var countryTemp in countriesList) { Country country = new Country(); country.name = countryTemp.Name; country.id = countryTemp.Id; country.active = countryTemp.Active; countryResponse.countries.Add(country); } return(JObject.Parse(JsonConvert.SerializeObject(countryResponse))); } else { Logger.Instance.WriteInLog(LogType.WARNING, "Something wrong ocurred while getting the countries"); return(JObject.Parse(JsonConvert.SerializeObject(new CountryResponse { countries = new List <Country>(), errors = "Could not get the countries" }))); } } catch (Exception ex) { Logger.Instance.WriteInLog(LogType.ERROR, "An error ocurred while getting the countries", null, ex.Message); return(JObject.Parse(JsonConvert.SerializeObject(new CountryResponse { countries = new List <Country>(), errors = ex.Message.ToString() }))); } }