/// <summary> /// Sorts using the selected option /// </summary> public List <MonsterModel> Sort(IEnumerable <MonsterModel> monsters, MonsterSortOption sortOption) { if (sortOption == MonsterSortOption.Name_Ascending) { monsters = monsters.OrderBy(x => x.Name); } else if (sortOption == MonsterSortOption.Name_Descending) { monsters = monsters.OrderByDescending(x => x.Name); } else if (sortOption == MonsterSortOption.Size_Ascending) { monsters = monsters.OrderBy(x => x.Size); } else if (sortOption == MonsterSortOption.Size_Descending) { monsters = monsters.OrderByDescending(x => x.Size); } else if (sortOption == MonsterSortOption.AC_Ascending) { monsters = monsters.OrderBy(x => ACToInt(x.AC)); } else if (sortOption == MonsterSortOption.AC_Descending) { monsters = monsters.OrderByDescending(x => ACToInt(x.AC)); } else if (sortOption == MonsterSortOption.Type_Ascending) { monsters = monsters.OrderBy(x => x.Type); } else if (sortOption == MonsterSortOption.Type_Descending) { monsters = monsters.OrderByDescending(x => x.Type); } else if (sortOption == MonsterSortOption.CR_Ascending) { monsters = monsters.OrderBy(x => _statService.CRToFloat(x.CR)); } else if (sortOption == MonsterSortOption.CR_Descending) { monsters = monsters.OrderByDescending(x => _statService.CRToFloat(x.CR)); } return(monsters.ToList()); }
/// <summary> /// Creates an instance of <see cref="MonsterSearchInput"/> /// </summary> public MonsterSearchInput(Compendium compendium, StringService stringService, StatService statService) { _compendium = compendium; _stringService = stringService; _statService = statService; foreach (MonsterSortOption sort in Enum.GetValues(typeof(MonsterSortOption))) { _sortOptions.Add(new KeyValuePair <MonsterSortOption, string>(sort, sort.ToString().Replace("_", " "))); } _sizes.Add(new KeyValuePair <CreatureSize, string>(CreatureSize.None, "Any Size")); foreach (CreatureSize size in Enum.GetValues(typeof(CreatureSize))) { if (size != CreatureSize.None) { _sizes.Add(new KeyValuePair <CreatureSize, string>(size, _stringService.GetString(size))); } } _alignments.Add(new KeyValuePair <Alignment, string>(Enums.Alignment.None, "Any Alignment")); foreach (Alignment alignment in Enum.GetValues(typeof(Alignment))) { if (alignment != Enums.Alignment.None) { _alignments.Add(new KeyValuePair <Alignment, string>(alignment, _stringService.GetString(alignment))); } } foreach (MonsterModel monster in _compendium.Monsters) { if (!_types.Any(x => x.Value.ToLower() == monster.Type.ToLower())) { _types.Add(new KeyValuePair <string, string>(monster.Type, _stringService.CapitalizeWords(monster.Type))); } int number = 0; if (!_crs.Any(x => x.Value == monster.CR) && (monster.CR.Contains("/") || Int32.TryParse(monster.CR, out number))) { _crs.Add(new KeyValuePair <string, string>(monster.CR, monster.CR)); } if (!String.IsNullOrWhiteSpace(monster.Environment)) { foreach (string environmentSplit in monster.Environment.Split(new char[] { ',' })) { string environment = environmentSplit.Trim(); if (!_environments.Any(x => x.Value.ToLower() == environment.ToLower())) { _environments.Add(new KeyValuePair <string, string>(environment, _stringService.CapitalizeWords(environment))); } } } } _types = _types.OrderBy(x => x.Value).ToList(); _types.Insert(0, new KeyValuePair <string, string>(null, "Any Type")); _crs = _crs.OrderBy(x => _statService.CRToFloat(x.Value)).ToList(); _crs.Insert(0, new KeyValuePair <string, string>("-", "Unknown")); _crs.Insert(0, new KeyValuePair <string, string>(null, "Any CR")); _environments = _environments.OrderBy(x => x.Value).ToList(); _environments.Insert(0, new KeyValuePair <string, string>(null, "Any Environment")); Reset(); }