title: where to put the validate logic? In Service or Repository?
body: <p>I have some logic like this, before save the stock into the db, i will check whether there is stock has the same stock code in the database. My question is where should I put the logic, in the service layer or repository layer. here is the sample code:<br/>
  option 1: put in the service layer, i put the IsAccountAlreadyExists Method in the service layer <br/></p>
  
  <pre><code>public override void Save(AccountInfo accountInfo)
  {
      using (var scope = new TransactionScope())
      {
          if(this.IsAccountAlreadyExists(accountInfo))
          {
              throw new AccountAlreadyExistedException(
                  "Account Code : " + accountInfo.AccountCode +
                  " already existed.");
          }
  
          accountRepository.Save(accountInfo);
              scope.Complete();
      }
  }
  </code></pre>
  
  <p>option 2: I will move the IsAccountAlreadyExists logic to the repository layer.</p>
  
  <pre><code>public override void Save(AccountInfo accountInfo)
  {
      try
      {
          using (var scope = new TransactionScope())
          {
              accountRepository.Save(accountInfo);
              scope.Complete();
          }
      }
      catch(AccountAlreadyExistedException e)
      {
          ...
      }
  }
  </code></pre>
  
  <p>what's your opinion?</p>