public static async Task <Species[]> GetSpeciesAsync(Zone zone) { List <Species> species = new List <Species>(); if (zone is null || zone.Id <= 0) { return(species.ToArray()); } using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Species WHERE id IN (SELECT species_id FROM SpeciesZones WHERE zone_id = $zone_id)")) { cmd.Parameters.AddWithValue("$zone_id", zone.Id); using (DataTable rows = await Database.GetRowsAsync(cmd)) foreach (DataRow row in rows.Rows) { species.Add(await SpeciesUtils.SpeciesFromDataRow(row)); } } return(species.ToArray()); }
public static async Task <Species[]> GetSpeciesAsync(Taxon taxon) { List <Species> species = new List <Species>(); if (taxon.type == TaxonRank.Species) { // Return all species with the same name as the taxon. species.AddRange(await SpeciesUtils.GetSpeciesAsync("", taxon.name)); } else if (taxon.type == TaxonRank.Genus) { // Return all species within this genus (rather than recursively calling this function for each species). using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM Species WHERE genus_id = $genus_id")) { cmd.Parameters.AddWithValue("$genus_id", taxon.id); using (DataTable table = await Database.GetRowsAsync(cmd)) foreach (DataRow row in table.Rows) { species.Add(await SpeciesUtils.SpeciesFromDataRow(row)); } } } else { // Get all subtaxa and call this function recursively to get the species from each of them. Taxon[] subtaxa = await GetSubtaxaAsync(taxon); foreach (Taxon t in subtaxa) { species.AddRange(await GetSpeciesAsync(t)); } } return(species.ToArray()); }