public async Task <IActionResult> AddQuestionAndAnswer(QOTDAnswer newAnswer, IFormCollection form) { if (!ModelState.IsValid) { return(RedirectToAction("About")); } int intIdt = _context.QOTDQuestion.Max(u => u.id); newAnswer.QuestionID = intIdt + 1; List <string> AuthorIds = new List <string> { }; foreach (string item in form["Authors"]) { AuthorIds.Add(item); } var successful = false; if (AuthorIds.Count() <= 1) { newAnswer.Author = AuthorIds[0]; successful = await _todoItemService.AddItemAsync(newAnswer); successful = await _todoItemService.AddQuestionAsync(newAnswer.Question); } else { List <QOTDAnswer> allAuthors = new List <QOTDAnswer> () { }; foreach (string author in AuthorIds) { newAnswer.Author = author; allAuthors.Add(newAnswer); successful = await _todoItemService.AddItemsAsync(allAuthors); } } if (!successful) { return(BadRequest("Could not add item.")); } return(RedirectToAction("About", new{ QuestionID = intIdt })); }