public async Task <IActionResult> Index() { var result = await questionProvider.GetAllItemsAsync(); if (!result.Item1.Success || result.Item1.IsError) { return(StatusCode(500)); } var model = new List <IndexQuestionViewModel>(); foreach (var q in result.Item2) { model.Add(new IndexQuestionViewModel { CanDelete = q.Owner == User.Identity.Name, Name = q.Name, Description = q.Description, Id = q.Id, TargettedAzureService = q.TargettedAzureService, QuestionType = q.QuestionType }); } return(View(model)); }
public async Task <IActionResult> Edit(string challengeId) { // Get the challenge details var challenge = await challengeProvider.GetItemAsync(challengeId); // Get the list of available questions var questions = await questionProvider.GetAllItemsAsync(); var userProfile = await userManager.GetUserAsync(User); var model = new VM.EditChallengeViewModel() { Questions = new List <VM.Question>(), Id = challengeId, Description = challenge.Item2.Description, IsPublic = challenge.Item2.IsPublic, IsLocked = challenge.Item2.IsLocked, OldIsPublic = challenge.Item2.IsPublic, Name = challenge.Item2.Name, ChallengeQuestions = challenge.Item2.Questions.OrderBy(p => p.Index) .Select(p => new VM.ChallengeQuestion { Description = p.Description, Difficulty = p.Difficulty, Id = p.Id, Index = p.Index, Name = p.Name, NextQuestionId = p.NextQuestionId, AssociatedQuestionId = p.AssociatedQuestionId }).ToList(), CurrentUserProfile = new EditChallengeViewModel.UserProfile { SubscriptionId = userProfile.SubscriptionId, TenantId = userProfile.TenantId, UserNameHashed = userProfile.UserNameHashed() }, AzureServiceCategory = challenge.Item2.AzureServiceCategory, Duration = challenge.Item2.Duration, PrereqLinks = challenge.Item2.PrereqLinks, WelcomeMessage = challenge.Item2.WelcomeMessage, TrackAndDeductPoints = challenge.Item2.TrackAndDeductPoints }; foreach (var q in questions.Item2) { if (!model.ChallengeQuestions.Exists(p => p.AssociatedQuestionId == q.Id)) { model.Questions.Add(new VM.Question() { AzureService = q.TargettedAzureService, Id = q.Id, Name = $"{q.Name} - (Level: {q.DifficultyString}) - {q.QuestionType}", Selected = false }); } } return(View(model)); }