src/main/java/seedu/address/logic/commands/commandAssign/AssignTeacherToCourseCommand.java
@Override
    protected void preprocessUndoableCommand(Model model) throws CommandException {
        ID courseID = this.assignDescriptor.getAssignID(PREFIX_COURSEID);
        ID staffID = this.assignDescriptor.getAssignID(PREFIX_TEACHERID);

        boolean courseExists = model.has(courseID, Constants.ENTITY_TYPE.COURSE);
        boolean staffExists = model.has(staffID, Constants.ENTITY_TYPE.STAFF);

        if (!courseExists) {
            throw new CommandException(MESSAGE_INVALID_COURSE_ID);
        } else if (!staffExists) {
            throw new CommandException(MESSAGE_INVALID_STAFF_ID);
        } else {
            Course foundCourse = (Course) model.get(courseID, Constants.ENTITY_TYPE.COURSE);
            Staff foundStaff = (Staff) model.get(staffID, Constants.ENTITY_TYPE.STAFF);

            Boolean isTeacher = foundStaff.isTeacher();

            if (!isTeacher) {
                throw new CommandException(MESSAGE_NOT_TEACHER);
            } else {
                boolean assignedCourseContainsTeacher = foundCourse.hasTeacher();
                boolean assignedTeacherContainsCourse = foundStaff.containsCourse(courseID);
                if (assignedCourseContainsTeacher) {
                    throw new CommandException(MESSAGE_COURSE_ALREADY_CONTAINS_TEACHER);
                } else if (assignedTeacherContainsCourse) {
                    throw new CommandException(MESSAGE_TEACHER_ALREADY_TEACHES_COURSE);
                }
            }
        }
    }
/**
     * Ensures that Teacher & Course exists and that they don't already contain each other.
     *
     * @param model
     */
Ensures that Teacher & Course exists and that they don't already contain each other.
@param model
Ensures that Teacher & Course exists and that they don ' t already contain each other . @param model
@Override
    protected void preprocessUndoableCommand(Model model) throws CommandException {
        ID courseID = this.assignDescriptor.getAssignID(PREFIX_COURSEID);
        ID staffID = this.assignDescriptor.getAssignID(PREFIX_TEACHERID);
        boolean courseExists = model.has(courseID, Constants.ENTITY_TYPE.COURSE);
        boolean staffExists = model.has(staffID, Constants.ENTITY_TYPE.STAFF);
        if (!courseExists) {
            throw new CommandException(MESSAGE_INVALID_COURSE_ID);
        } else if (!staffExists) {
            throw new CommandException(MESSAGE_INVALID_STAFF_ID);
        } else {
            Course foundCourse = (Course) model.get(courseID, Constants.ENTITY_TYPE.COURSE);
            Staff foundStaff = (Staff) model.get(staffID, Constants.ENTITY_TYPE.STAFF);
            Boolean isTeacher = foundStaff.isTeacher();
            if (!isTeacher) {
                throw new CommandException(MESSAGE_NOT_TEACHER);
            } else {
                boolean assignedCourseContainsTeacher = foundCourse.hasTeacher();
                boolean assignedTeacherContainsCourse = foundStaff.containsCourse(courseID);
                if (assignedCourseContainsTeacher) {
                    throw new CommandException(MESSAGE_COURSE_ALREADY_CONTAINS_TEACHER);
                } else if (assignedTeacherContainsCourse) {
                    throw new CommandException(MESSAGE_TEACHER_ALREADY_TEACHES_COURSE);
                }
            }
        }
    }
@ Override protected void preprocessUndoableCommand ( Model model ) throws CommandException { ID courseID = this . assignDescriptor . getAssignID ( PREFIX_COURSEID ) ; ID staffID = this . assignDescriptor . getAssignID ( PREFIX_TEACHERID ) ; boolean courseExists = model . has ( courseID , Constants . ENTITY_TYPE . COURSE ) ; boolean staffExists = model . has ( staffID , Constants . ENTITY_TYPE . STAFF ) ; if ( ! courseExists ) { throw new CommandException ( MESSAGE_INVALID_COURSE_ID ) ; } else if ( ! staffExists ) { throw new CommandException ( MESSAGE_INVALID_STAFF_ID ) ; } else { Course foundCourse = ( Course ) model . get ( courseID , Constants . ENTITY_TYPE . COURSE ) ; Staff foundStaff = ( Staff ) model . get ( staffID , Constants . ENTITY_TYPE . STAFF ) ; Boolean isTeacher = foundStaff . isTeacher ( ) ; if ( ! isTeacher ) { throw new CommandException ( MESSAGE_NOT_TEACHER ) ; } else { boolean assignedCourseContainsTeacher = foundCourse . hasTeacher ( ) ; boolean assignedTeacherContainsCourse = foundStaff . containsCourse ( courseID ) ; if ( assignedCourseContainsTeacher ) { throw new CommandException ( MESSAGE_COURSE_ALREADY_CONTAINS_TEACHER ) ; } else if ( assignedTeacherContainsCourse ) { throw new CommandException ( MESSAGE_TEACHER_ALREADY_TEACHES_COURSE ) ; } } } }
Ensures that Teacher & Course exists and that they don't already contain each other.
Ensures that Teacher & Course exists and that they don ' t already contain each other .