Files
xDataService/Interfaces/IXBaseRepository.cs
T
2024-01-25 04:41:17 +03:30

273 lines
7.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
using xModels.Base;
using xModels.Dtos;
namespace xDataService.Interfaces {
/// <summary>
/// a Base Repository Interface for Manipulate
/// an Entity in DataBase
/// </summary>
/// <typeparam name="T"></typeparam>
public interface IXBaseRepository<T, TKey> : IDisposable
where T : XBaseEntity<TKey> {
//
#region Add ...
/// <summary>
/// add a new Entity ...
/// </summary>
/// <param name="item"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<T> AddAsync (
T item,
bool saveChanges = true
);
/// <summary>
/// add or update an Entity (add if not exists/update if exists) ...
/// </summary>
/// <param name="item"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<T> AddOrUpdateAsync (
T item,
bool saveChanges = true
);
/// <summary>
/// add a range of new Entities ...
/// </summary>
/// <param name="items"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task AddRangeAsync (
IEnumerable<T> items,
bool saveChanges = true
);
#endregion
//
#region Remove ...
/// <summary>
/// remove an Entity by it's Id ...
/// </summary>
/// <param name="id"></param>
/// <param name="softDelete"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<T> RemoveAsync (
TKey id,
bool softDelete = true,
bool saveChanges = true
);
/// <summary>
/// remove an Entity ...
/// </summary>
/// <param name="item"></param>
/// <param name="softDelete"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<T> RemoveAsync (
T item,
bool softDelete = true,
bool saveChanges = true
);
/// <summary>
/// remove a range of exists Entities ...
/// </summary>
/// <param name="items"></param>
/// <param name="softDelete"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task RemoveRangeAsync (
IEnumerable<T> items,
bool softDelete = true,
bool saveChanges = true
);
#endregion
//
#region Retrieve ...
/// <summary>
/// retrieve whole items as queryable ...
/// </summary>
/// <returns></returns>
IQueryable<T> AsQueryable ();
/// <summary>
/// retrieve an Entity by it's Id ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="containsDetail"></param>
/// <returns></returns>
Task<T> GetAsync (
TKey id,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
/// <summary>
/// retrieve all exists Entities ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="containsDetail"></param>
/// <returns></returns>
Task<IEnumerable<T>> GetAllAsync (
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
/// <summary>
/// find an Entity by providing a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="containsDetail"></param>
/// <returns></returns>
Task<T> FindOneAsync (
Expression<Func<T, bool>> whereClause,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
/// <summary>
/// find a collection of Entities by proving a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="containsDetail"></param>
/// <returns></returns>
Task<IEnumerable<T>> FindManyAsync (
Expression<Func<T, bool>> whereClause,
bool ignoreSoftDeleteds = true,
bool containsDetail = false
);
/// <summary>
/// retrieve Entities based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<XQueryResult<T>> QueryAsync (
XQuery query,
bool ignoreSoftDeleteds = true
);
/// <summary>
/// retrieve Entities based on XQuery Pagination structure by providing a Conditional Expression ...
/// </summary>
/// <param name="whereClause"></param>
/// <param name="query"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<XQueryResult<T>> ConditionalQueryAsync (
Expression<Func<T, bool>> whereClause,
XQuery query,
bool ignoreSoftDeleteds = true
);
#endregion
//
#region Update ...
/// <summary>
/// Update an Entity values ...
/// </summary>
/// <param name="id"></param>
/// <param name="item"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<T> UpdateAsync (
TKey id,
T item,
bool saveChanges = true
);
/// <summary>
/// Update a range of Entities ...
/// </summary>
/// <param name="items"></param>
/// <param name="saveChanges"></param>
/// <returns></returns>
Task<bool> UpdateRangeAsync (
IEnumerable<T> items,
bool saveChanges = true
);
#endregion
//
#region Count ...
/// <summary>
/// count all exists Entities ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<int> CountAsync (bool ignoreSoftDeleteds = true);
/// <summary>
/// count all exists Entities Pages by providing page size ...
/// </summary>
/// <param name="pageSize"></param>
/// <param name="totalItems"></param>
/// <returns></returns>
Task<int> PagesCountAsync (
int pageSize,
int? totalItems = null
);
#endregion
//
#region Exists ...
/// <summary>
/// Check an Entity exists or not ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <returns></returns>
Task<bool> IsExistsAsync (
TKey id,
bool ignoreSoftDeleteds = true
);
#endregion
//
#region Unit Of Work ...
/// <summary>
/// Save all unsaved Transactions on DbContext ...
/// used fo Unit Of Works Design Pattern ...
/// </summary>
/// <returns></returns>
Task<int> SaveChangesAsync ();
#endregion
//
#region Key ...
TKey GetKey (T item);
void SetKey (
ref T item,
TKey id
);
Task<T> HandleKeyAsync (T item);
#endregion
//
#region Detach ...
void Detach (T item);
void Detach (IEnumerable<T> items);
void Detach (XQueryResult<T> query);
void Detach (XPageResponse<T> page);
#endregion
}
}