public ActionResult AddQuestion(SingleQuestionUpload squ, HttpPostedFileBase upload) { int ex = squ.ExamId; if (ModelState.IsValid) { var kdk = new ExamQuestion { Examination = _examinationRepository.GetExaminationData(squ.ExamId), QuestionContent = squ.Question }; var quest = _examinationRepository.SaveQuestion(kdk, upload); //add options var eo1 = new ExamOption { OptionContent = squ.Option1, ExamQuestion = quest }; var op1 = _examinationRepository.SavExamOption(eo1); var eo2 = new ExamOption { OptionContent = squ.Option2, ExamQuestion = quest }; var op2 = _examinationRepository.SavExamOption(eo2); var eo3 = new ExamOption { OptionContent = squ.Option3, ExamQuestion = quest }; var op3 = _examinationRepository.SavExamOption(eo3); var eo4 = new ExamOption { OptionContent = squ.Option4, ExamQuestion = quest }; var op4 = _examinationRepository.SavExamOption(eo4); var eo5 = new ExamOption { OptionContent = squ.Option5, ExamQuestion = quest }; var op5 = _examinationRepository.SavExamOption(eo5); int value = squ.AnswerIdentifier; //save answer switch (value) { case 1: var ans1 = new ExamAnswer { ExamQuestion = quest, ExamOption = op1 }; _examinationRepository.SaveAnswer(ans1); break; case 2: var ans2 = new ExamAnswer { ExamQuestion = quest, ExamOption = op2 }; _examinationRepository.SaveAnswer(ans2); break; case 3: var ans3 = new ExamAnswer { ExamQuestion = quest, ExamOption = op3 }; _examinationRepository.SaveAnswer(ans3); break; case 4: var ans4 = new ExamAnswer { ExamQuestion = quest, ExamOption = op4 }; _examinationRepository.SaveAnswer(ans4); break; case 5: var ans5 = new ExamAnswer { ExamQuestion = quest, ExamOption = op5 }; _examinationRepository.SaveAnswer(ans5); break; } } TempData["notification"] = "The Question has been successfully uploaded"; return(RedirectToAction("Qustion", new { examId = ex })); }