From 2d6d1cc8bba57168eb5b5f049bacb0414f9545ec Mon Sep 17 00:00:00 2001 From: Greg Edwards Date: Fri, 8 May 2015 20:21:21 -0400 Subject: [PATCH] Allow searching pokemon by natdex number. --- web/controls/PokemonSource.ashx.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/web/controls/PokemonSource.ashx.cs b/web/controls/PokemonSource.ashx.cs index 649aa180..75e1f646 100644 --- a/web/controls/PokemonSource.ashx.cs +++ b/web/controls/PokemonSource.ashx.cs @@ -18,7 +18,17 @@ namespace PkmnFoundations.Web.controls Pokedex.Pokedex pokedex = AppStateHelper.Pokedex(context.Application); String iso = Format.ToIso639_1(lang); query = query.ToLowerInvariant(); - IEnumerable data = pokedex.Species.Where(pair => pair.Value.Name[iso].ToLowerInvariant().Contains(query)).OrderBy(pair => pair.Key).Take(rows).Select(pair => pair.Value); + int natDex = 0; + Int32.TryParse(query, out natDex); + + Func, bool> filter; + if (natDex > 0) + filter = pair => pair.Key == natDex; + else + filter = pair => pair.Value.Name[iso].ToLowerInvariant().Contains(query); + + IEnumerable data; + data = pokedex.Species.Where(filter).OrderBy(pair => pair.Key).Take(rows).Select(pair => pair.Value); DataTable dt = new DataTable(); dt.Columns.Add("Text", typeof(String));