* Paging criterias added in BaseSpecification. New paginated specification added (CatalogFilterPaginatedSpecification) . EFRepository cleaned up and paging implementation added. Usage of the new paging infrastructure in CatalogService (Web and WebRazor). * Use IReadOnlyList<T> instead of List<T> as return type from repositories. * - Ordering possibility added in the specification. - Evaluation of the specification placed in separate class.
48 lines
1.7 KiB
C#
48 lines
1.7 KiB
C#
using Microsoft.eShopWeb.ApplicationCore.Interfaces;
|
|
using System;
|
|
using System.Linq.Expressions;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
|
{
|
|
public abstract class BaseSpecification<T> : ISpecification<T>
|
|
{
|
|
protected BaseSpecification(Expression<Func<T, bool>> criteria)
|
|
{
|
|
Criteria = criteria;
|
|
}
|
|
public Expression<Func<T, bool>> Criteria { get; }
|
|
public List<Expression<Func<T, object>>> Includes { get; } = new List<Expression<Func<T, object>>>();
|
|
public List<string> IncludeStrings { get; } = new List<string>();
|
|
public Expression<Func<T, object>> OrderBy { get; private set; }
|
|
public Expression<Func<T, object>> OrderByDescending { get; private set; }
|
|
|
|
public int Take { get; private set; }
|
|
public int Skip { get; private set; }
|
|
public bool isPagingEnabled { get; private set; } = false;
|
|
|
|
protected virtual void AddInclude(Expression<Func<T, object>> includeExpression)
|
|
{
|
|
Includes.Add(includeExpression);
|
|
}
|
|
protected virtual void AddInclude(string includeString)
|
|
{
|
|
IncludeStrings.Add(includeString);
|
|
}
|
|
protected virtual void ApplyPaging(int skip, int take)
|
|
{
|
|
Skip = skip;
|
|
Take = take;
|
|
isPagingEnabled = true;
|
|
}
|
|
protected virtual void ApplyOrderBy(Expression<Func<T, object>> orderByExpression)
|
|
{
|
|
OrderBy = orderByExpression;
|
|
}
|
|
protected virtual void ApplyOrderByDescending(Expression<Func<T, object>> orderByDescendingExpression)
|
|
{
|
|
OrderByDescending = orderByDescendingExpression;
|
|
}
|
|
}
|
|
}
|