Files
xPushService/Interfaces/IXBaseEntityProvider.cs
T
2026-05-28 02:31:01 +03:30

211 lines
7.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore.Query;
using xDataService.Configuration;
using xDataService.Interfaces;
using xIdentityService.Interfaces;
using xModels.Base;
using xModels.Dtos;
using xPushService.Base;
namespace xPushService.Interfaces
{
/// <summary>
/// a Provider is a way to Manipulate Data using Repository or Services and Contains Push
/// notifications ability ...
/// </summary>
/// <typeparam name="TEntity"></typeparam>
/// <typeparam name="TKey"></typeparam>
public interface IXBaseEntityProvider<TEntity, TKey, THub>
where TEntity : XBaseEntity<TKey>
where THub : XBaseEntityHub<TEntity, TKey>
{
//
#region Props ...
IHubContext<THub> Hub { get; }
IXIdentityProvider IdentityProvider { get; }
IXBaseRepository<TEntity, TKey> Repository { get; }
XDataServiceConfiguration DataConfiguration { get; }
#endregion
//
#region Actions ...
/// <summary>
/// add a new Item ...
/// </summary>
/// <param name="item"></param>
/// <param name="saveChanges"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TEntity> AddAsync(
TEntity item,
bool saveChanges = true,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// Update an Item values ...
/// </summary>
/// <param name="id"></param>
/// <param name="item"></param>
/// <param name="saveChanges"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TEntity> UpdateAsync(
TKey id,
TEntity item,
bool saveChanges = true,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// remove an Item by it's Id ...
/// </summary>
/// <param name="id"></param>
/// <param name="softDelete"></param>
/// <param name="saveChanges"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TEntity> RemoveAsync(
TKey id,
bool softDelete = true,
bool saveChanges = true,
string connectionId = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// count all exists Items ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<int> CountAsync(
bool ignoreSoftDeleteds = true,
CancellationToken cancellationToken = default
);
/// <summary>
/// Check an Item exists or not ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<bool> IsExistsAsync(
TKey id,
bool ignoreSoftDeleteds = true,
CancellationToken cancellationToken = default
);
/// <summary>
/// retrieve an Item by it's Id ...
/// </summary>
/// <param name="id"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TEntity> GetAsync(
TKey id,
bool ignoreSoftDeleteds = true,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// retrieve all exists Items ...
/// </summary>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<TEntity>> GetAllAsync(
bool ignoreSoftDeleteds = true,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// find an Item by providing a Conditional Expression ...
/// </summary>
/// <param name="predicate"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<TEntity> FindOneAsync(
Expression<Func<TEntity, bool>> predicate,
bool ignoreSoftDeleteds = true,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// find a collection of Items by proving a Conditional Expression ...
/// </summary>
/// <param name="predicate"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<IEnumerable<TEntity>> FindManyAsync(
Expression<Func<TEntity, bool>> predicate,
bool ignoreSoftDeleteds = true,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
CancellationToken cancellationToken = default
);
/// <summary>
/// retrieve Items based on XQuery Pagination structure ...
/// </summary>
/// <param name="query"></param>
/// <param name="ignoreSoftDeleteds"></param>
/// <param name="predicate"></param>
/// <param name="orderBuilder"></param>
/// <param name="includeBuilder"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XQueryResult<TEntity>> QueryAsync(
XQuery query,
bool ignoreSoftDeleteds = true,
Expression<Func<TEntity, bool>> predicate = null,
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBuilder = null,
Func<IQueryable<TEntity>, IIncludableQueryable<TEntity, object>> includeBuilder = null,
CancellationToken cancellationToken = default
);
#endregion
//
#region Hub Actions ...
/// <summary>
/// Send Custom Push Message ...
/// </summary>
/// <param name="action"></param>
/// <param name="payLoad"></param>
/// <param name="connectionId"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task SendPush(
string action,
string payLoad,
string connectionId = null,
CancellationToken cancellationToken = default
);
#endregion
}
}