public async Task <ActionResult> Create(IFormCollection collection, Questions questions, Answers answers) { try { var created = await questionsRepo.Add(questions); if (created == null) { throw new Exception("Invalid Entry"); } var created2 = await answersRepo.Add(answers); if (created2 == null) { throw new Exception("Invalid Entry"); } return(RedirectToAction(nameof(Index))); } catch (Exception ex) { Console.WriteLine("Create geeft error " + ex.Message); ModelState.AddModelError("", "Create actie is mislukt voor " + questions.QuestionID); return(View(questions)); } }
public async Task <ActionResult> CreateAsync(IFormCollection collection, Answers answer, Guid id) { answer.AnswerID = Guid.NewGuid(); answer.QuestionId = id; var quiz = await quizrepo.GetQuizByQuestionID(id); try { var created = await answerRepo.Add(answer); if (created == null) { throw new Exception("Invalid Entry"); } return(RedirectToAction("Index", "QuestionsAnswers", new { id = quiz.QuizID })); } catch (Exception ex) { Console.WriteLine("Create geeft error " + ex.Message); ModelState.AddModelError("", "Create actie is mislukt voor " + answer.AnswerID); return(View(answer)); } }
public async Task <IActionResult> AddOrUpdate(AnswersDTO item) { if (ModelState.IsValid) { if (item.Id > 0) { await _repo.Update(item); } else { await _repo.Add(item); } return(PartialView("_Answers", await _repo.GetList())); } return(Content("Wypełnij wymagane pole")); }