public ActionResult GiveAssignmentReq() { LoginDetails loginDetails = (LoginDetails)Session["loginDetails"]; if (loginDetails == null) { return(RedirectToAction("PageNotFoundError", "Home")); } int user = (int)Session["user"]; if (user != 1) { return(RedirectToAction("PageNotFoundError", "Home")); } object o = Session["selectedClass"]; if (o == null) { return(RedirectToAction("PageNotFoundError", "Home")); } int id = (int)o; Course course = data.GetCourse(id); if (course == null) { return(RedirectToAction("PageNotFoundError", "Home")); } if (course.Active == false) { return(RedirectToAction("PageNotFoundError", "Home")); } int total; if (!int.TryParse(Request["TotalQuestions"], out total)) { ViewBag.IsWrongTotal = true; return(View("ScheduleQuiz", course)); } if (total <= 0) { ViewBag.IsWrongTotal = true; return(View("ScheduleQuiz", course)); } Assignment assignment = new Assignment(); assignment.Title = Request["Title"]; assignment.Content = Request["Content"]; List <AssignmentQuestion> questions = new List <AssignmentQuestion>(); for (int i = 1; i <= total; i++) { AssignmentQuestion question = new AssignmentQuestion(); question.Question = Request["Question" + i]; questions.Add(question); } data.AddAssignment(course, assignment, questions); return(RedirectToAction("GiveAssignment")); }