private bool StringMatchesSpeciesName(string name, ISpecies species) { name = name.ToLower(); return(name == species.Name.ToLower() || name == species.GetShortName().ToLower() || name == species.GetFullName().ToLower() || (!string.IsNullOrEmpty(species.GetCommonName()) && name == species.GetCommonName().ToLower())); }
private async Task <string> BuildTitleAsync(ISpecies species) { if (species is null) { throw new ArgumentNullException(nameof(species)); } // Pages are created based on the first/primary common name (where available). // The full species name is added as a redirect. string title = string.Empty; if (!string.IsNullOrWhiteSpace(species.GetCommonName())) { title = species.GetCommonName(); } else { IEnumerable <string> commonNames = species.CommonNames; if (commonNames.Count() > 0) { title = commonNames.First(); } else { title = species.GetFullName(); } } // If the title is empty for whatever reason (common names set to whitespace, for example), use the species' binomial name. if (string.IsNullOrWhiteSpace(title)) { title = species.GetFullName(); } // Trim any surrounding whitespace from the title. if (!string.IsNullOrEmpty(title)) { title = title.Trim(); } return(title); }
public static string GetWikiPageTitle(ISpecies species) { // This is the same process as used in SpeciesPageBuilder.BuildTitleAsync. // #todo Instead of being copy-pasted, this process should be in its own function used by both classes. string title; if (!string.IsNullOrWhiteSpace(species.GetCommonName())) { title = species.GetCommonName(); } else { title = species.GetFullName(); } title = title.SafeTrim(); return(title); }
public async Task SetSpeciesCommonName(string genusName, string speciesName, string commonName) { ISpecies species = await GetSpeciesOrReplyAsync(genusName, speciesName); if (species.IsValid()) { if (string.IsNullOrWhiteSpace(commonName)) { // If the given common name is empty, erase all common names associated with this species. species.CommonNames.Clear(); await Db.UpdateSpeciesAsync(species); await ReplySuccessAsync($"Successfully removed all common names from **{species.GetShortName()}**."); } else { // Otherwise, add the common name to the database. // The difference between this and the "+common" command is that this one overwrites the value stored in the "Species" table with the first common name. // This field is deprected at this point. List <string> commonNames = new List <string> { commonName }; commonNames.AddRange(species.CommonNames); species.CommonNames.Clear(); species.CommonNames.AddRange(commonNames); await Db.UpdateSpeciesAsync(species); await ReplySuccessAsync($"**{species.GetShortName()}** is now commonly known as the **{species.GetCommonName().ToTitle()}**."); } } }