public ActionResponse AssignCourse(CourseAssign courseAssign)
        {
            ActionResponse response = new ActionResponse();
            try
            {
                bool isAlreadyAssigned = aTeacherGateway.IsAlreadyAssigned(courseAssign);
                if (isAlreadyAssigned)
                {
                    response.Class = "danger";
                    response.Message = "This course is already assigned to another teacher.";
                    return response;
                }

                aTeacherGateway.AssignCourse(courseAssign);
                response.Class = "success";
                response.Message = "Course Assigned successfully.";
            }
            catch (SqlException ex)
            {
                response.Class = "warning";
                response.Message = ex.Message;
            }
            return response;
        }
        public void AssignCourse(CourseAssign courseAssign)
        {
            string query = "INSERT INTO CourseAssign (TeacherId, CourseId, IsCurrent) VALUES (@teacherId, @courseId, @isCurrent)";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();
                command.Parameters.Add("teacherId", sqlDbType: SqlDbType.Int);
                command.Parameters["teacherId"].Value = courseAssign.TeacherId;

                command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                command.Parameters["courseId"].Value = courseAssign.CourseId;

                command.Parameters.Add("isCurrent", sqlDbType: SqlDbType.Bit);
                command.Parameters["isCurrent"].Value = courseAssign.IsCurrent;

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
        public bool IsAlreadyAssigned(CourseAssign courseAssign)
        {
            string query = "SELECT * FROM CourseAssign WHERE CourseId =@courseId AND IsCurrent =1";
            using (connection = new SqlConnection(connectionString))
            using (SqlCommand command = new SqlCommand(query, connection))
            {
                command.Parameters.Clear();

                command.Parameters.Add("courseId", sqlDbType: SqlDbType.Int);
                command.Parameters["courseId"].Value = courseAssign.CourseId;

                connection.Open();
                SqlDataReader reader = command.ExecuteReader();
                return reader.HasRows;
            }
        }
 public ActionResult AssignCourse(CourseAssign courseAssign)
 {
     ViewBag.response = aTeacherManager.AssignCourse(courseAssign);
     ViewBag.Departments = aDepartmentManager.GetAllDepartments();
     return View();
 }