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

        boolean courseExists = model.has(courseID, Constants.ENTITY_TYPE.COURSE);
        boolean assignmentExists = model.has(assignmentID, Constants.ENTITY_TYPE.ASSIGNMENT);

        if (!courseExists) {
            throw new CommandException(MESSAGE_INVALID_COURSE_ID);
        } else if (!assignmentExists) {
            throw new CommandException(MESSAGE_INVALID_ASSIGNMENT_ID);
        } else {
            Course assignedCourse = (Course) model.get(courseID, Constants.ENTITY_TYPE.COURSE);
            Assignment assigningAssignment = (Assignment) model.get(assignmentID, Constants.ENTITY_TYPE.ASSIGNMENT);

            boolean assignedCourseContainsAssignment = assignedCourse.containsAssignment(assignmentID);
            boolean assigningAssignmentContainsCourse = assigningAssignment.isAssignedToCourse();

            if (assigningAssignmentContainsCourse) {
                throw new CommandException(MESSAGE_INVALID_ASSIGNMENT_ALREADY_ASSIGNED);
            }
            if (assignedCourseContainsAssignment) {
                throw new CommandException(MESSAGE_INVALID_COURSE_HAS_ASSIGNMENT);
            }
        }
    }
/**
     * This step is performed to ensure that all specified ModelObjects exists and that they do not already contain
     * the modelobjects that we want to assign to it.
     *
     * @param model
     */
This step is performed to ensure that all specified ModelObjects exists and that they do not already contain
the modelobjects that we want to assign to it.

@param model
This step is performed to ensure that all specified ModelObjects exists and that they do not already contain the modelobjects that we want to assign to it . @param model
@Override
    protected void preprocessUndoableCommand(Model model) throws CommandException {
        ID courseID = this.assignDescriptor.getAssignID(PREFIX_COURSEID);
        ID assignmentID = this.assignDescriptor.getAssignID(PREFIX_ASSIGNMENTID);
        boolean courseExists = model.has(courseID, Constants.ENTITY_TYPE.COURSE);
        boolean assignmentExists = model.has(assignmentID, Constants.ENTITY_TYPE.ASSIGNMENT);
        if (!courseExists) {
            throw new CommandException(MESSAGE_INVALID_COURSE_ID);
        } else if (!assignmentExists) {
            throw new CommandException(MESSAGE_INVALID_ASSIGNMENT_ID);
        } else {
            Course assignedCourse = (Course) model.get(courseID, Constants.ENTITY_TYPE.COURSE);
            Assignment assigningAssignment = (Assignment) model.get(assignmentID, Constants.ENTITY_TYPE.ASSIGNMENT);
            boolean assignedCourseContainsAssignment = assignedCourse.containsAssignment(assignmentID);
            boolean assigningAssignmentContainsCourse = assigningAssignment.isAssignedToCourse();
            if (assigningAssignmentContainsCourse) {
                throw new CommandException(MESSAGE_INVALID_ASSIGNMENT_ALREADY_ASSIGNED);
            }
            if (assignedCourseContainsAssignment) {
                throw new CommandException(MESSAGE_INVALID_COURSE_HAS_ASSIGNMENT);
            }
        }
    }
@ Override protected void preprocessUndoableCommand ( Model model ) throws CommandException { ID courseID = this . assignDescriptor . getAssignID ( PREFIX_COURSEID ) ; ID assignmentID = this . assignDescriptor . getAssignID ( PREFIX_ASSIGNMENTID ) ; boolean courseExists = model . has ( courseID , Constants . ENTITY_TYPE . COURSE ) ; boolean assignmentExists = model . has ( assignmentID , Constants . ENTITY_TYPE . ASSIGNMENT ) ; if ( ! courseExists ) { throw new CommandException ( MESSAGE_INVALID_COURSE_ID ) ; } else if ( ! assignmentExists ) { throw new CommandException ( MESSAGE_INVALID_ASSIGNMENT_ID ) ; } else { Course assignedCourse = ( Course ) model . get ( courseID , Constants . ENTITY_TYPE . COURSE ) ; Assignment assigningAssignment = ( Assignment ) model . get ( assignmentID , Constants . ENTITY_TYPE . ASSIGNMENT ) ; boolean assignedCourseContainsAssignment = assignedCourse . containsAssignment ( assignmentID ) ; boolean assigningAssignmentContainsCourse = assigningAssignment . isAssignedToCourse ( ) ; if ( assigningAssignmentContainsCourse ) { throw new CommandException ( MESSAGE_INVALID_ASSIGNMENT_ALREADY_ASSIGNED ) ; } if ( assignedCourseContainsAssignment ) { throw new CommandException ( MESSAGE_INVALID_COURSE_HAS_ASSIGNMENT ) ; } } }
This step is performed to ensure that all specified ModelObjects exists and that they do not already contain
 the modelobjects that we want to assign to it.
This step is performed to ensure that all specified ModelObjects exists and that they do not already contain the modelobjects that we want to assign to it .