using Microsoft.eShopWeb.ApplicationCore.Interfaces; using System; using System.Linq.Expressions; using System.Collections.Generic; using Microsoft.eShopWeb.ApplicationCore.Helpers.Query; namespace Microsoft.eShopWeb.ApplicationCore.Specifications { public abstract class BaseSpecification : ISpecification { protected BaseSpecification(Expression> criteria) { Criteria = criteria; } public Expression> Criteria { get; } public List>> Includes { get; } = new List>>(); public List IncludeStrings { get; } = new List(); public Expression> OrderBy { get; private set; } public Expression> OrderByDescending { get; private set; } public Expression> GroupBy { 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> includeExpression) { Includes.Add(includeExpression); } protected virtual void AddIncludes(Func, IIncludeQuery> includeGenerator) { var includeQuery = includeGenerator(new IncludeAggregator()); IncludeStrings.AddRange(includeQuery.Paths); } 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> orderByExpression) { OrderBy = orderByExpression; } protected virtual void ApplyOrderByDescending(Expression> orderByDescendingExpression) { OrderByDescending = orderByDescendingExpression; } //Not used anywhere at the moment, but someone requested an example of setting this up. protected virtual void ApplyGroupBy(Expression> groupByExpression) { GroupBy = groupByExpression; } } }