public ActionResult EnrollCourse(StudentEnrollCourses studentEnrollCourses)
        {
            bool result = false;

            _studentManager.ValidateStudent(studentEnrollCourses);



            if (ModelState.IsValid)
            {
                if (_studentManager.Message == null)
                {
                    result = _studentEnrollCoursesManager.Save(studentEnrollCourses);
                    if (result)
                    {
                        ViewBag.SuccessMessage = "Student Enrolled Successfully";
                    }
                    else
                    {
                        ViewBag.ErrorMessage = "Student Enrolled Failed";
                    }
                }
                else
                {
                    ViewBag.ErrorMessage = _studentManager.Message;
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Student Enrolled Failed";
            }

            ViewBag.Student = _studentManager.GetAllStudent();
            return(View());
        }
Example #2
0
        public StudentEnrollCourses GetStudentByEnrollCourseId(StudentEnrollCourses studentEnrollCourses)
        {
            Command.CommandText = @"Select * from StudentEnroleCourse where StudentId='" + studentEnrollCourses.StudentId + "' and CourseId='" + studentEnrollCourses.CourseId + "'";
            Connection.Open();
            SqlDataReader reader = Command.ExecuteReader();

            StudentEnrollCourses sec = null;

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    sec = new StudentEnrollCourses()
                    {
                        Id           = (int)reader["Id"],
                        StudentId    = (int)reader["StudentId"],
                        CourseId     = (int)reader["CourseId"],
                        DepartmentId = (int)reader["DepartmentId"]
                    };
                }
            }

            reader.Close();
            Connection.Close();
            return(sec);
        }
        public void ValidateStudent(StudentEnrollCourses studentEnrollCourses)
        {
            StudentEnrollCourses st = IsStudentEnrolledTheCourseBefore(studentEnrollCourses);

            if (st != null)
            {
                Message = "Student Already Enrolled this Course";
            }
        }
Example #4
0
        public bool Save(StudentEnrollCourses studentEnrollCourses)
        {
            bool result = false;

            string query = @"INSERT INTO StudentEnroleCourse(StudentId,CourseId,DepartmentId,CreatedDate) Values (" + studentEnrollCourses.StudentId + "," + studentEnrollCourses.CourseId + "," + studentEnrollCourses.DepartmentId + ",'" + studentEnrollCourses.CreatedDateTime + "')";

            Command.CommandText = query;

            Connection.Open();
            result = Command.ExecuteNonQuery() > 0;
            Connection.Close();


            return(result);
        }
 private StudentEnrollCourses IsStudentEnrolledTheCourseBefore(StudentEnrollCourses studentEnrollCourses)
 {
     return(_studentGateway.GetStudentByEnrollCourseId(studentEnrollCourses));
 }
 public bool Save(StudentEnrollCourses studentEnrollCourses)
 {
     return(_studentEnrollCoursesGateway.Save(studentEnrollCourses));
 }