public async Task <IActionResult> Index() { var result = await challengeProvider.GetAllItemsAsync(); var model = new IndexChallengeViewModel { Challenges = mapper.Map <IList <VM.ChallengeList> >(result.Item2) }; model.AzureServiceCategories = AzureChallenge.UI.Models.AzureServicesCategoryMapping.CategoryName; model.AzureServiceCategory = AzureChallenge.UI.Models.AzureServicesCategoryMapping.CategoryName[0]; model.FilesAvailableForImport = new List <KeyValuePair <string, string> >(); // Get the list of available import files from the public GitHub repo using (var client = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Get, "https://api.github.com/repos/istavrinides/AzureChallenge/contents/Exports"); request.Headers.Add("User-Agent", "AzChallenge"); var response = await client.SendAsync(request); List <GitHubFiles> filesInRepo = JsonConvert.DeserializeObject <List <GitHubFiles> >(await response.Content.ReadAsStringAsync()); foreach (var file in filesInRepo) { if (file.name.EndsWith(".zip")) { model.FilesAvailableForImport.Add(new KeyValuePair <string, string>(file.download_url, file.name)); } } } return(View(model)); }
public async Task <IActionResult> Index() { var model = new IndexViewModel { Challenges = new List <Challenge>() }; var challengesResponse = await challengesProvider.GetAllItemsAsync(); if (challengesResponse.Item1.Success) { model.Challenges = challengesResponse.Item2 .Where(c => c.IsPublic) .Select(c => new Models.ChallengeViewModels.Challenge { Description = c.Description, Id = c.Id, Name = c.Name, CurrentQuestionId = c.Questions.Where(q => q.Index == 0).FirstOrDefault()?.Id, IsComplete = false, IsUnderway = false, AzureCategory = c.AzureServiceCategory, WelcomeMessage = c.WelcomeMessage, PrereqLinks = c.PrereqLinks }) .ToList(); } var user = await _userManager.GetUserAsync(User); var userChallengesResponse = await userChallengesProvider.GetItemAsync(user.Id); if (userChallengesResponse.Item1.Success) { if (userChallengesResponse.Item2 != null) { foreach (var challenge in userChallengesResponse.Item2.Challenges) { // If a user is enrolled in a challenge, check if not finished and set the continuation question if (!challenge.Completed) { var challengeInModel = model.Challenges.Where(p => p.Id == challenge.ChallengeId).FirstOrDefault(); if (challengeInModel != null) { challengeInModel.CurrentQuestionId = challenge.CurrentQuestion; challengeInModel.IsUnderway = true; } } else { var challengeInModel = model.Challenges.Where(p => p.Id == challenge.ChallengeId).FirstOrDefault(); if (challengeInModel != null) { challengeInModel.IsComplete = true; } } } } } return(View(model)); }