public bool IsStudentCurseExists(EnrollCourse enrollCourse)
        {
            connection.ConnectionString = connectionString;
            string query = "SELECT * FROM EnrollCourse WHERE (RegNo=@RegNo AND CourseId=@CourseId)";

            SqlCommand command = new SqlCommand();
            command.CommandText = query;
            command.Connection = connection;
            command.Parameters.Add("RegNo", SqlDbType.VarChar);
            command.Parameters["RegNo"].Value = enrollCourse.RegNo;
            command.Parameters.Add("CourseId", SqlDbType.VarChar);
            command.Parameters["CourseId"].Value = enrollCourse.CourseId;



            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            bool StudentCurse = false;

            if (reader.HasRows)
            {
                StudentCurse = true;
            }
            connection.Close();

            return StudentCurse;
        }
        public decimal Save(EnrollCourse enrollCourse)
        {

            connection.ConnectionString = connectionString;

            string query = "INSERT INTO EnrollCourse (RegNo,CourseId,Date) VALUES(@RegNo,@CourseId,@Date)";

            SqlCommand command = new SqlCommand(query, connection);
            command.Parameters.Clear();
            command.Parameters.Add("RegNo", SqlDbType.VarChar);
            command.Parameters["RegNo"].Value = enrollCourse.RegNo;
            //command.Parameters.Add("RegNo", SqlDbType.VarChar);
            //command.Parameters["RegNo"].Value = student.Date.ToString("yyyy") + "-" + student.ContactNo + "-" + student.Id;

            command.Parameters.Add("Date", SqlDbType.DateTime);
            command.Parameters["Date"].Value = enrollCourse.Date;
            command.Parameters.Add("CourseId", SqlDbType.Int);
            command.Parameters["CourseId"].Value = enrollCourse.CourseId;



            connection.Open();
            int rowAffected = command.ExecuteNonQuery();
            connection.Close();
            return rowAffected;
        }
 public ActionResult EnrollInACourse(EnrollCourse enrollCourse)
 {
     ViewBag.Message = enrollCourseManager.Save(enrollCourse);
     List<Student> students = studentManager.GetAllStudent();
     ViewBag.StudentList = students;
     ModelState.Clear();
     return View();
 }
 public string Save(EnrollCourse enrollCourse)
 {
     if (enrollCourseGateway.IsStudentCurseExists(enrollCourse))
     {
         return "This student is already enrolled in this course";
     }
     else
     {
         if (enrollCourseGateway.Save(enrollCourse) > 0)
         {
             return "Saved";
         }
         else
         {
             return "Save failed";
         }
     }
 }