forked from dotnet-architecture/eShopOnWeb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into Removing-unused-directives
- Loading branch information
Showing
10 changed files
with
114 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/ApplicationCore/Specifications/CatalogFilterPaginatedSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
|
||
namespace Microsoft.eShopWeb.ApplicationCore.Specifications | ||
{ | ||
public class CatalogFilterPaginatedSpecification : BaseSpecification<CatalogItem> | ||
{ | ||
public CatalogFilterPaginatedSpecification(int skip, int take, int? brandId, int? typeId) | ||
: base(i => (!brandId.HasValue || i.CatalogBrandId == brandId) && | ||
(!typeId.HasValue || i.CatalogTypeId == typeId)) | ||
{ | ||
ApplyPaging(skip, take); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.eShopWeb.ApplicationCore.Entities; | ||
using Microsoft.eShopWeb.ApplicationCore.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace Microsoft.eShopWeb.Infrastructure.Data | ||
{ | ||
public class SpecificationEvaluator<T> where T : BaseEntity | ||
{ | ||
public static IQueryable<T> GetQuery(IQueryable<T> inputQuery, ISpecification<T> specification) | ||
{ | ||
var query = inputQuery; | ||
|
||
// modify the IQueryable using the specification's criteria expression | ||
if (specification.Criteria != null) | ||
query = query.Where(specification.Criteria); | ||
|
||
// Includes all expression-based includes | ||
query = specification.Includes.Aggregate(query, | ||
(current, include) => current.Include(include)); | ||
|
||
// Include any string-based include statements | ||
query = specification.IncludeStrings.Aggregate(query, | ||
(current, include) => current.Include(include)); | ||
|
||
// Apply ordering if expressions are set | ||
if (specification.OrderBy != null) | ||
query = query.OrderBy(specification.OrderBy); | ||
else if (specification.OrderByDescending != null) | ||
query = query.OrderByDescending(specification.OrderByDescending); | ||
|
||
// Apply paging if enabled | ||
if (specification.isPagingEnabled) | ||
{ | ||
query = query.Skip(specification.Skip) | ||
.Take(specification.Take); | ||
} | ||
return query; | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters