public IActionResult Add(IEnumerable <int> questions) { //Todo : add to all applicable teamanswers var answers = _context.Questions.Where(e => questions.Any(q => q == e.QuestionID)); var teams = _context.Teams; var teamAnswers = new List <TeamAnswers>(); foreach (var team in teams) { foreach (var answer in answers) { var teamAnswer = new TeamAnswers(answer, team); if (!_context.TeamAnswers.Contains(teamAnswer)) { teamAnswers.Add(teamAnswer); } } } _context.TeamAnswers.AddRange(teamAnswers); _context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Index(TeamAnswers answers) { var correct = _context.Answer .Where(e => e.QuestionID == answers.QuestionID && e.Correct) .FirstOrDefault(); if (answers.Answer.Equals(correct.Text)) { answers.Correct = true; } else { answers.Correct = false; } _context.TeamAnswers.Update(answers); _context.SaveChanges(); return(RedirectToAction("Index")); }
private void GetAnswersSelectedTeam(Team selectedTeam) { if (selectedTeam == null) { return; } SelectedTeam = selectedTeam; RoundsSelectionMode = "None"; RaisePropertyChanged(() => RoundsSelectionMode); TeamAnswersPerRound.Clear(); TeamAnswers.Clear(); selectedTeam.TeamAnswers.ToList().ForEach(a => { TeamAnswers.Add(a); }); RoundsSelectionMode = "Single"; RaisePropertyChanged(() => RoundsSelectionMode); }