title: Who is responsible for checking state?
body: <p>I'm currently building a consent management system consisting of 3 layers:</p>
  <ul>
  <li>Handlers/Controllers (Rest)</li>
  <li>Services (Logic)</li>
  <li>Repositories (Microsoft SQL)</li>
  </ul>
  <p><strong>This is the scenario:</strong></p>
  <p>I'm fetching the identifier (Id) from a model inside of the database. But before that, I have to check if a boolean of another model is set to true or false. I had a discussion with one of our engineers on how to implement his, and furthermore who is responsible for the checking: Business logic or repository layer by SQL queries.</p>
  <p><strong>Solution 1:</strong>
  Fetch the whole model/instance from the repository layer by two parameters and then explicitly check the state of the boolean. (true/false) Using the following query:</p>
  <p><code>SELECT * FROM [ApplicationUserMapping] WHERE Uuid = @Uuid AND ApplicationUuid=@ApplicationUuid;</code></p>
  <p>Code inside the business logic:</p>
  <pre><code>if !applicationUserMapping.HasConsent {
      // User is NOT allowed to proceed -&gt; Error messaging -&gt; Logging -&gt; etc.
  }
  
  // User is allowed to proceed -&gt; Continue code block
  </code></pre>
  <p><strong>Solution 2:</strong>
  Or write and execute a query that checks if the state of the boolean. (true/false) The repository is now responsible for checking the state. And return the values depending on the outcome of the query.</p>
  <p><code>SELECT * FROM [ApplicationUserMapping] WHERE Uuid = @Uuid AND ApplicationUuid=@ApplicationUuid AND HasConsent = 1;</code></p>
  <p><strong>Solution 3:</strong>
  If you understand my scenario and have a better solution please provide it.</p>