title: Best way to simplify boolean check in c# with a lot of different possibilities
body: <p>How can I reduce this code? I have transferId, weekId and lineId and I want to be able to query the database based on if the url parameters where given or not.</p>
  
  <p>Example:</p>
  
  <p>route/Query?transferId=5325&amp;lineId=10</p>
  
  <p>or</p>
  
  <p>route/Query?weekdId=11</p>
  
  <p>and so on...</p>
  
  <pre><code>public async Task&lt;ICollection&lt;TransferEntity&gt;&gt; GetQueryAsync(string transferId, int? weekId, int? lineId)
      {
          if (Helpers.NullOrWhiteSpaceAll(transferId, weekId.ToString(), lineId.ToString()))
          {
              return null;
          }
          else if (!Helpers.NullOrWhiteSpaceAny(transferId, weekId.ToString(), lineId.ToString()))
          {
              return await _context.Transfers.Where(x =&gt; x.TransferId == transferId &amp;&amp; x.WeekId == weekId &amp;&amp; x.LineId == lineId).ToListAsync();
          }
          if (Helpers.NullOrWhiteSpace(transferId))
          {
              if (!Helpers.NullOrWhiteSpaceAny(weekId, lineId))
              {
                  return await _context.Transfers.Where(x =&gt; x.WeekId == weekId &amp;&amp; x.LineId == lineId).ToListAsync();
              }
              else if (!Helpers.NullOrWhiteSpace(weekId))
              {
                  return await _context.Transfers.Where(x =&gt; x.WeekId == weekId).ToListAsync();
              }
              else
              {
                  return await _context.Transfers.Where(x =&gt; x.LineId == lineId).ToListAsync();
              }
          }
          else if (Helpers.NullOrWhiteSpace(weekId))
          {
              if (!Helpers.NullOrWhiteSpaceAny(transferId, lineId.ToString()))
              {
                  return await _context.Transfers.Where(x =&gt; x.TransferId == transferId &amp;&amp; x.LineId == lineId).ToListAsync();
              }
              else if (!Helpers.NullOrWhiteSpace(transferId))
              {
                  return await _context.Transfers.Where(x =&gt; x.TransferId == transferId).ToListAsync();
              }
              else
              {
                  return await _context.Transfers.Where(x =&gt; x.LineId == lineId).ToListAsync();
              }
          }
          else
          {
              return await _context.Transfers.Where(x =&gt; x.TransferId == transferId &amp;&amp; x.WeekId == weekId).ToListAsync();
          }
      }
  </code></pre>