コード例 #1
0
        public ActionResult AddExam(ExamViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var currentUser   = AccountServiceCaller.Get(User.Identity.Name);
            var userOrganizer = OrganizerServiceCaller.Get(currentUser.OrganizerId);
            var newExam       = new ExamModel();

            newExam.OrganizerId = userOrganizer.Id;
            newExam.CourseName  = model.CourseName;
            newExam.Hour        = model.Hour;
            newExam.Date        = model.ExamDay;
            newExam.Room        = model.ExamRoom;
            newExam.Difficulty  = model.Difficulty;

            try
            {
                ExamServiceCaller.Add(newExam);
                return(RedirectToAction("Index", "Exam"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
コード例 #2
0
        public ActionResult EditExam(int id)
        {
            ViewBag.CourseId = id;
            var exam      = ExamServiceCaller.Get(id);
            var examModel = new ExamEditViewModel()
            {
                CourseName = exam.CourseName,
                Difficulty = exam.Difficulty,
                ExamDay    = exam.Date,
                ExamRoom   = exam.Room,
                Hour       = exam.Hour
            };

            return(View(examModel));
        }
コード例 #3
0
        public ActionResult EditExam(int id, ExamEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var exam = ExamServiceCaller.Get(id);

            if (!String.IsNullOrEmpty(model.CourseName))
            {
                exam.CourseName = model.CourseName;
            }
            if (model.ExamDay != null)
            {
                exam.Date = model.ExamDay ?? new DateTime();
            }
            if (!String.IsNullOrEmpty(model.Hour.ToString()))
            {
                exam.Hour = model.Hour ?? 0;
            }
            if (!String.IsNullOrEmpty(model.Difficulty.ToString()))
            {
                exam.Difficulty = model.Difficulty ?? 0;
            }
            if (!String.IsNullOrEmpty(model.ExamRoom))
            {
                exam.Room = model.ExamRoom;
            }
            try
            {
                ExamServiceCaller.Update(exam);
                return(RedirectToAction("Index", "Exam"));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
コード例 #4
0
        public ActionResult Delete(int id)
        {
            ExamServiceCaller.Delete(id);

            return(RedirectToAction("Index", "Exam"));
        }