I have an Account and Opportunities for it. These Opportunities have time intervals: Start Date and Close Date. I want to prohibit the creation of Opportunities whose intervals overlap with the intervals of already created Opportunities. How can I do this? Now I'm getting my error from trigger and 'Yes!' from Helper. What is wrong here?

**Here is my Trigger Helper:**

```
public class ApartmentHelper {
public static List<Opportunity> oldRentContracts = [SELECT Id, Start_Date__c, CloseDate, Days__c, Total_cost__c, Net_income__c, AccountId
                                                    FROM Opportunity
                                                    WHERE StageName != 'Closed Won' AND StageName != 'Closed Won'];

public static void handleAfterInsert(List<Opportunity> newRentContracts) {
    for(Opportunity newOpp : newRentContracts){
        for(Opportunity oldOpp : oldRentContracts){

            if((newOpp.AccountId == oldOpp.AccountId) &&
              ((newOpp.Start_Date__c >= oldOpp.Start_Date__c && newOpp.Start_Date__c <= oldOpp.CloseDate) ||
               (newOpp.CloseDate >= oldOpp.Start_Date__c && newOpp.CloseDate <= oldOpp.CloseDate) ||
               (newOpp.Start_Date__c <= oldOpp.Start_Date__c && newOpp.CloseDate >= oldOpp.CloseDate))) {
                   System.debug('No');
            } else{
                System.debug('Yes!'); //I see this
            }
        }
    }
}
}

```

**Trigger:**

```
trigger ApartmentTrigger on Opportunity (before insert, before update) {  
  if(Trigger.isBefore){
    if(Trigger.isInsert || Trigger.isUpdate){
        ApartmentHelper.handleAfterInsert(Trigger.new);
        Trigger.new[0].addError('Ouch!'); //But I see this error too
    }
  }
}

```

Thank you for answers.