title: Filtering based on multiple parameters using LINQ?
body: <p>I am working on an e-commerce website using ASP.NET MVC 5, EF6 and LINQ. I have a <strong>Products</strong> table in my database. In my UI, I have multiple parameters for the filtering of my products:</p>
  
  <ul>
  <li>checkboxes for different categories</li>
  <li>minimum and maximum prices</li>
  <li>checkboxes for different colors</li>
  </ul>
  
  <p>And I have written this action method:</p>
  
  <pre><code>[HttpPost]
  public PartialViewResult FilterProducts(int[] categoriesIds, decimal minPrice, decimal? maxPrice, string[] colors)
  {
          if (categoriesIds == null)
          {
              var randomProducts = db.Products
                  .OrderBy(p =&gt; Guid.NewGuid());
              return PartialView("_LoadProducts", randomProducts.ToList());
          }
          else
          {
              var filteredProducts = db.Products
                  .Where(p =&gt; categoriesIds.Contains(p.CategoryId)
                      &amp;&amp; (p.DiscountedPrice &gt;= minPrice
                          &amp;&amp; p.DiscountedPrice &lt;= maxPrice || maxPrice == null));
  
              if (colors != null)
              {
                  filteredProducts = filteredProducts
                      .Where(p =&gt; colors.Contains(p.Color));
              }
              return PartialView("_LoadProducts", filteredProducts.ToList());
          }
  }
  </code></pre>
  
  <p>This works fine. But I'm confused to whether this can be improved? It includes a lot of if/else statements just to filter products. Is there any problem with my design overall? Are there any best practices?
  Any help will be highly appreciated. Thanks.</p>