private async Task <IReadOnlyCollection <GameItemViewModel> > GetGameItemsAsync(string itemName) { var items = await db.GetGameItemsAsync(); var itemsWithoutRecipes = items.Where(x => !x.IsRecipe); List <GameItemViewModel> gameItems = new List <GameItemViewModel>(); foreach (var item in itemsWithoutRecipes) { string localizedName = await db.GetLocalizationTextAsync(String.Format("DOTA_Tooltip_Ability_{0}", item.Name)); if (!String.IsNullOrEmpty(itemName)) { if (localizedName.ToLower().Contains(itemName.ToLower())) { gameItems.Add(new GameItemViewModel() { Cost = item.Cost, Name = localizedName, Description = await db.GetLocalizationTextAsync(String.Format("DOTA_Tooltip_ability_{0}_Description", item.Name)), Lore = await db.GetLocalizationTextAsync(String.Format("DOTA_Tooltip_ability_{0}_Lore", item.Name)), Id = item.Id, IsRecipe = item.IsRecipe, SecretShop = item.IsAvailableAtSecretShop, SideShop = item.IsAvailableAtSideShop, IconPath = String.Format("http://cdn.dota2.com/apps/dota2/images/items/{0}_lg.png", item.IsRecipe ? "recipe" : item.Name.Replace("item_", "")), }); } } else { gameItems.Add(new GameItemViewModel() { Cost = item.Cost, Name = localizedName, Description = await db.GetLocalizationTextAsync(String.Format("DOTA_Tooltip_ability_{0}_Description", item.Name)), Lore = await db.GetLocalizationTextAsync(String.Format("DOTA_Tooltip_ability_{0}_Lore", item.Name)), Id = item.Id, IsRecipe = item.IsRecipe, SecretShop = item.IsAvailableAtSecretShop, SideShop = item.IsAvailableAtSideShop, IconPath = String.Format("http://cdn.dota2.com/apps/dota2/images/items/{0}_lg.png", item.IsRecipe ? "recipe" : item.Name.Replace("item_", "")), }); } } var abilities = await db.GetItemAbilitiesAsync(); foreach (var itemViewModel in gameItems) { await AddAbilityToItemViewModelAsync(itemViewModel, abilities); } return(gameItems.AsReadOnly()); }
public async Task <ActionResult> Index() { HomeViewModel viewModel = new HomeViewModel(); IReadOnlyDictionary <uint, LeagueModel> leagues = null; try { leagues = await db.GetLeaguesAsync(); } catch (HttpRequestException) { } // maybe log this in the future, for now do nothing viewModel.LeagueCount = leagues != null ? (int?)leagues.Count : null; var gameItems = await db.GetGameItemsAsync(); var schema = await db.GetSchemaAsync(); var heroes = await db.GetHeroDetailsAsync(); var heroAbilities = await db.GetHeroAbilitiesAsync(); viewModel.HeroCount = heroes.Count; viewModel.HeroAbilityCount = heroAbilities.Count; viewModel.ShopItemCount = schema.Items.Count; viewModel.InGameItemCount = gameItems.Count; int?liveLeagueGameCount = null; try { liveLeagueGameCount = await db.GetLiveLeagueGameCountAsync(); } catch (HttpRequestException) { // live league game endpoints return 500 or 404 randomly and without warning // maybe log this in the future, for now do nothing } viewModel.LiveLeagueGameCount = liveLeagueGameCount; var playerCounts = await db.GetPlayerCountsAsync(); viewModel.InGamePlayerCount = playerCounts.InGamePlayerCount; viewModel.DailyPeakPlayerCount = playerCounts.DailyPeakPlayerCount; viewModel.AllTimePeakPlayerCount = playerCounts.AllTimePeakPlayerCount; LiveLeagueGameOverviewViewModel topLiveLeagueGame = null; try { topLiveLeagueGame = await GetTopLiveLeagueGameAsync(); } catch (HttpRequestException) { // live league game endpoints return 500 or 404 randomly and without warning // maybe log this in the future, for now do nothing } viewModel.TopLiveLeagueGame = topLiveLeagueGame; viewModel.RandomHero = GetRandomHeroViewModel(heroes); await SetupRandomItems(viewModel, gameItems); var dotaBlogFeedItems = db.GetDotaBlogFeedItemsAsync(); viewModel.DotaBlogFeedItems = AutoMapperConfiguration.Mapper.Map < IReadOnlyCollection <DotaBlogFeedItem>, IReadOnlyCollection <DotaBlogFeedItemViewModel> > (dotaBlogFeedItems); return(View(viewModel)); }