Merge branch 'master' into Removing-unused-directives
This commit is contained in:
@@ -7,10 +7,11 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
|
||||
public interface IAsyncRepository<T> where T : BaseEntity
|
||||
{
|
||||
Task<T> GetByIdAsync(int id);
|
||||
Task<List<T>> ListAllAsync();
|
||||
Task<List<T>> ListAsync(ISpecification<T> spec);
|
||||
Task<IReadOnlyList<T>> ListAllAsync();
|
||||
Task<IReadOnlyList<T>> ListAsync(ISpecification<T> spec);
|
||||
Task<T> AddAsync(T entity);
|
||||
Task UpdateAsync(T entity);
|
||||
Task DeleteAsync(T entity);
|
||||
Task<int> CountAsync(ISpecification<T> spec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,5 +12,6 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
|
||||
T Add(T entity);
|
||||
void Update(T entity);
|
||||
void Delete(T entity);
|
||||
int Count(ISpecification<T> spec);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,5 +9,11 @@ namespace Microsoft.eShopWeb.ApplicationCore.Interfaces
|
||||
Expression<Func<T, bool>> Criteria { get; }
|
||||
List<Expression<Func<T, object>>> Includes { get; }
|
||||
List<string> IncludeStrings { get; }
|
||||
Expression<Func<T, object>> OrderBy { get; }
|
||||
Expression<Func<T, object>> OrderByDescending { get; }
|
||||
|
||||
int Take { get; }
|
||||
int Skip { get; }
|
||||
bool isPagingEnabled { get;}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,12 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
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)
|
||||
{
|
||||
@@ -23,5 +29,19 @@ namespace Microsoft.eShopWeb.ApplicationCore.Specifications
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user