public async Task <ICollection <Hero> > GetHeroes() { var cachedHeroes = _prismicCacheProvider.TryGetPrismicCacheItem <ICollection <Hero> >(await _prismicService.GetMasterRef(), CacheKeys.Heroes); if (cachedHeroes != null) { return(cachedHeroes); } var queryResult = await _prismicService.QueryApi <PrismicHero>("[[at(document.type, \"hero\")]]"); if (queryResult != null && queryResult.Any()) { var prismicHeroes = queryResult.Select(x => x.Data); var inGameCategories = await GetInGameCategories(); var roles = await GetRoles(); var universes = await GetUniverses(); foreach (var hero in prismicHeroes) { hero.Talents = hero.DeserialisableTalents.Cast <Talent>().ToList(); hero.Universe = universes.SingleOrDefault(x => x.Id == hero.UniverseLink.Id); foreach (var categoryLink in hero.InGameCategoryLinks) { var category = inGameCategories.SingleOrDefault(x => x.Id == categoryLink.Category.Id); if (category != null) { hero.InGameCategories.Add(category); } } foreach (var roleLink in hero.RoleLinks) { var role = roles.SingleOrDefault(x => x.Id == roleLink.Role.Id); if (role != null) { hero.Roles.Add(role); } } } foreach (var hero in prismicHeroes.Where(x => x.MustBePairedWithLink.IsValid)) { hero.MustBePairedWith = prismicHeroes.SingleOrDefault(x => x.Id == hero.MustBePairedWithLink.Id); } var retVal = prismicHeroes.Cast <Hero>().ToList(); _prismicCacheProvider.SetPrismicCacheItem(queryResult.First().Data.PrismicRef, CacheKeys.Heroes, retVal); return(retVal); } return(new List <Hero>()); }
public async Task <PrismicAboutPage> GetAboutPage() { var cachedAboutPage = _cacheProvider.TryGetPrismicCacheItem <PrismicAboutPage>(await _prismicService.GetMasterRef(), CacheKeys.AboutPage); if (cachedAboutPage != null) { return(cachedAboutPage); } var queryResult = await _prismicService.QueryApi <PrismicAboutPage>("[[at(document.type, \"about_page\")]]"); if (queryResult != null && queryResult.Any()) { var retVal = queryResult.Select(x => x.Data).Cast <PrismicAboutPage>().SingleOrDefault(); _cacheProvider.SetPrismicCacheItem(queryResult.First().Data.PrismicRef, CacheKeys.AboutPage, retVal); return(retVal); } return(null); }