|
using System; |
|
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Linq.Expressions; |
|
using System.Threading.Tasks; |
|
using PROJECT.Business.Dto; |
|
|
|
namespace PROJECT.Business.Repositories |
|
{ |
|
public interface IRepository<T> : IDisposable where T : class |
|
{ |
|
/// <summary> |
|
/// Returns all <typeparamref name="T" /> records as a List. Takes an optional <paramref name="orderBy" />. |
|
/// </summary> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <returns></returns> |
|
List<T> GetAll(Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns all <typeparamref name="T" /> records as an Async List. Takes an optional <paramref name="orderBy" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <example> |
|
/// this is an example |
|
/// </example> |
|
/// <returns></returns> |
|
Task<List<T>> GetAllAsync(Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns all <typeparamref name="T" /> records as an Async List. Using <paramref name="select" /> to return desire |
|
/// to columns. |
|
/// Takes an optional <paramref name="orderBy" />. Must be used with await! |
|
/// </summary> |
|
/// <typeparam name="TResult"></typeparam> |
|
/// <param name="select">Example x => x.Id or x => new {x.Id, x.Name}</param> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <returns></returns> |
|
Task<List<TResult>> GetAllAsync<TResult>(Expression<Func<T, TResult>> select, |
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns a single <typeparamref name="T" /> record based on the <paramref name="id" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="id"></param> |
|
/// <returns></returns> |
|
Task<T> GetAsync(int id); |
|
|
|
/// <summary> |
|
/// Returns a single <typeparamref name="T" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="predicate">Where clause</param> |
|
/// <returns></returns> |
|
Task<T> GetAsync(Expression<Func<T, bool>> predicate); |
|
|
|
/// <summary> |
|
/// Returns a single <typeparamref name="T" /> using the <paramref name="predicate" /> as a |
|
/// Where clause and using <paramref name="select" /> to return desire to columns. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <typeparam name="TResult"></typeparam> |
|
/// <param name="predicate">Example x => x.Id == 4</param> |
|
/// <param name="select">Example x => x.Id or x => new {x.Id, x.Name}</param> |
|
/// <returns></returns> |
|
Task<TResult> GetAsync<TResult>(Expression<Func<T, bool>> predicate, Expression<Func<T, TResult>> select); |
|
|
|
/// <summary> |
|
/// Returns single <typeparamref name="T" /> using <paramref name="select" /> to return desire to columns. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <typeparam name="TResult"></typeparam> |
|
/// <param name="id">Record Id</param> |
|
/// <param name="select">Example x => x.Id or x => new {x.Id, x.Name}</param> |
|
/// <returns></returns> |
|
Task<TResult> GetAsync<TResult>(int id, Expression<Func<T, TResult>> select); |
|
|
|
/// <summary> |
|
/// Returns a <see cref="List{T}" /> using the <paramref name="predicate" /> as a Where clause. |
|
/// Takes an optional <paramref name="orderBy" />. Must be used with await! |
|
/// </summary> |
|
/// <param name="predicate">Example x => x.Id == 4</param> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <returns> |
|
/// <see cref="List{T}" /> |
|
/// </returns> |
|
Task<List<T>> FindByAsync(Expression<Func<T, bool>> predicate, |
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns a <see cref="List{T}" /> using the <paramref name="predicate" /> as a |
|
/// Where clause and using <paramref name="select" /> to return desire to columns. |
|
/// Takes an optional <paramref name="orderBy" />. Must be used with await! |
|
/// </summary> |
|
/// <typeparam name="TResult"></typeparam> |
|
/// <param name="predicate">Example x => x.Id == 4</param> |
|
/// <param name="select">Example x => x.Id or x => new {x.Id, x.Name}</param> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <returns></returns> |
|
Task<List<TResult>> FindByAsync<TResult>(Expression<Func<T, bool>> predicate, |
|
Expression<Func<T, TResult>> select, |
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns <see cref="PagedEntities{T}" />using the <paramref name="predicate" /> as a |
|
/// Where clause and using. Takes an optional <paramref name="orderBy" />. Must be used with await! |
|
/// </summary> |
|
/// <param name="predicate">Example x => x.Id == 4</param> |
|
/// <param name="page">Skip the number of <paramref name="itemsPerPage" /></param> |
|
/// <param name="itemsPerPage">Number of records to retrieve</param> |
|
/// <param name="orderBy">Example: x => x.OrderBy(y => y.Name).ThenBy(y => y.Profit)</param> |
|
/// <returns></returns> |
|
Task<PagedEntities<T>> FindByPageAsync(Expression<Func<T, bool>> predicate, int page, int itemsPerPage, |
|
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Returns <see cref="PagedEntities{T}" />using the <paramref name="predicate" /> as a |
|
/// Where clause and using <paramref name="select" /> to return desire to columns. |
|
/// Takes an optional <paramref name="orderBy" />. Must be used with await! |
|
/// </summary> |
|
/// <param name="predicate">Example x => x.Id == 4</param> |
|
/// <param name="select">Example x => x.Id or x => new {x.Id, x.Name}</param> |
|
/// <param name="page">Skip the number of <paramref name="itemsPerPage" /></param> |
|
/// <param name="itemsPerPage">Number of records to retrieve</param> |
|
/// <param name="orderBy"></param> |
|
/// <returns></returns> |
|
Task<PagedEntities<T>> FindByPageAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, T>> select, |
|
int page, int itemsPerPage, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null); |
|
|
|
/// <summary> |
|
/// Asynchronously inserts <typeparamref name="T" />, calls <see cref="SaveAsync" /> and returns |
|
/// <typeparamref name="T" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="t"></param> |
|
/// <returns></returns> |
|
Task<T> InsertAsync(T t); |
|
|
|
/// <summary> |
|
/// Asynchronously deletes <typeparamref name="T" /> and calls <see cref="SaveAsync" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="t"></param> |
|
/// <returns></returns> |
|
Task DeleteAsync(T t); |
|
|
|
/// <summary> |
|
/// Sets <typeparamref name="T" />'s State to Modified and calls <see cref="SaveAsync" />. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <param name="t"></param> |
|
/// <returns></returns> |
|
Task UpdateAsync(T t); |
|
|
|
/// <summary> |
|
/// Calls the DALs save method. Probably should *NOT* be used by itself. |
|
/// Must be used with await! |
|
/// </summary> |
|
/// <returns></returns> |
|
Task SaveAsync(); |
|
} |
|
} |