public async Task <IActionResult> GetSubregions([FromRoute] string region) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <string> stringList = new List <string>(); stringList = await _context.Countries.Where(r => r.Region == region).Select(c => c.Subregion).Distinct().OrderBy(r => 1).ToListAsync(); List <Subregions> subregionsList = new List <Subregions>(); foreach (string s in stringList) { Subregions sr = new Subregions(); sr.SubregionName = s; subregionsList.Add(sr); } if (subregionsList == null) { return(NotFound()); } return(Ok(subregionsList)); }
public IEnumerable <Subregions> GetSubregions() { List <string> stringList = new List <string>(); stringList = _context.Countries.Select(c => c.Subregion).Distinct().OrderBy(r => 1).ToList(); List <Subregions> subregionsList = new List <Subregions>(); foreach (string s in stringList) { Subregions sr = new Subregions(); sr.SubregionName = s; subregionsList.Add(sr); } return(subregionsList); }