コード例 #1
0
        public ActionResult InsertExam()
        {
            var model = new InsertExamModel();

            ViewBag.ExamSubjects = new AppDbContext().Subjects
                                   .Select(s => new SelectListItem()
            {
                Value = s.Id.ToString(),
                Text  = s.Name
            });

            return(View());
        }
コード例 #2
0
        public ActionResult InsertExam(InsertExamModel model)
        {
            var ctx = new AppDbContext();

            var subject = ctx.Subjects.Where(s => s.Id == model.SelectedExamSubject).SingleOrDefault();

            if (subject == null)
            {
                throw new Exception("Subject does not exist.");
            }

            var insertExam = new Exam(null, subject, model.EstimatedAmountOfStudents, null, model.ExamNeedsComputers, model.ExamSurveillantAvailable, new TimeSpan(0, model.ExamDuration, 0));

            ctx.Exams.Add(insertExam);

            ctx.SaveChanges();

            return(RedirectToAction("InsertExam"));
        }