Beispiel #1
0
        public ViewResult EnrollInCourse(CourseEnrollment courseEnrollment)
        {
            CourseEnrollmentViewModel viewModel = new CourseEnrollmentViewModel
            {
                Students = StudentGateway.GetStudents()
            };

            if (!ModelState.IsValid)
            {
                viewModel.CourseEnrollment = courseEnrollment;

                ViewBag.Message = "Saved";

                return(View(viewModel));
            }

            int rowAffected = StudentGateway.Enroll(courseEnrollment);

            if (rowAffected > 0)
            {
                ViewBag.Message = "Saved";
            }
            else
            {
                ViewBag.Message = "Error";
            }

            return(View(viewModel));
        }
        public ActionResponse Enroll(Enrollment aEnrollment)
        {
            ActionResponse response = new ActionResponse();

            try
            {
                bool isAlreadyEnrolled = aStudentGateway.IsAlreadyEnrolled(aEnrollment);
                if (isAlreadyEnrolled)
                {
                    response.Class   = "danger";
                    response.Message = "This student is already enrolled in this course.";
                    return(response);
                }

                aStudentGateway.Enroll(aEnrollment);
                response.Class   = "success";
                response.Message = "Enrollment successfully completed.";
            }
            catch (SqlException ex)
            {
                response.Class   = "warning";
                response.Message = ex.Message;
            }
            return(response);
        }