From 35e1e08d50e30dd7fbbf249a19e836bae8a3edcf Mon Sep 17 00:00:00 2001 From: Hadi Khazaee Asl Date: Thu, 7 May 2026 12:55:27 +0330 Subject: [PATCH] refactor renew ... --- Interfaces/IXBaseProvider.cs | 4 + Providers/XBaseProvider.cs | 233 ++++++++++++++++++++++------------- 2 files changed, 148 insertions(+), 89 deletions(-) diff --git a/Interfaces/IXBaseProvider.cs b/Interfaces/IXBaseProvider.cs index 383f1c2..af0d690 100644 --- a/Interfaces/IXBaseProvider.cs +++ b/Interfaces/IXBaseProvider.cs @@ -51,12 +51,14 @@ namespace xPushService.Interfaces /// /// /// + /// /// /// Task UpdateAsync( TKey id, TDto item, bool saveChanges = true, + string connectionId = null, CancellationToken cancellationToken = default ); @@ -66,12 +68,14 @@ namespace xPushService.Interfaces /// /// /// + /// /// /// Task RemoveAsync( TKey id, bool softDelete = true, bool saveChanges = true, + string connectionId = null, CancellationToken cancellationToken = default ); diff --git a/Providers/XBaseProvider.cs b/Providers/XBaseProvider.cs index fa34dcb..2b6973d 100644 --- a/Providers/XBaseProvider.cs +++ b/Providers/XBaseProvider.cs @@ -32,8 +32,6 @@ namespace xPushService.Providers // #region Actions ... - // - #region Add ... /// /// add a new Dto ... /// @@ -50,7 +48,7 @@ namespace xPushService.Providers ) { // - TDto result = await RepositoryService.AddAsync( + var result = await RepositoryService.AddAsync( item: item, saveChanges: saveChanges, cancellationToken: cancellationToken @@ -71,87 +69,86 @@ namespace xPushService.Providers return result; } - // - #region Update ... /// /// Update an Dto values ... /// /// /// /// + /// /// /// public async Task UpdateAsync( TKey id, TDto item, bool saveChanges = true, + string connectionId = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.UpdateAsync( + id: id, + item: item, + saveChanges: saveChanges, + cancellationToken: cancellationToken + ); - /// - /// Update a range of Dtos ... - /// - /// - /// - /// - /// - public async Task UpdateRangeAsync( - IEnumerable items, - bool saveChanges = true, - CancellationToken cancellationToken = default - ); - #endregion + // + if (!result.IsNullOrDefault()) + { + // + await SendPush( + action: XBaseEntityHubAction.Update.GetStringValue(), + payLoad: result.ToJSON(camelCase: true), + connectionId: connectionId + ); + } + + // + return result; + } - // - #region Remove ... /// /// remove an Dto by it's Id ... /// /// /// /// + /// /// /// public async Task RemoveAsync( TKey id, bool softDelete = true, bool saveChanges = true, + string connectionId = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.RemoveAsync( + id: id, + softDelete: softDelete, + saveChanges: saveChanges, + cancellationToken: cancellationToken + ); - /// - /// remove an Dto ... - /// - /// - /// - /// - /// - /// - public async Task RemoveAsync( - TDto item, - bool softDelete = true, - bool saveChanges = true, - CancellationToken cancellationToken = default - ); + // + if (!result.IsNullOrDefault()) + { + // + await SendPush( + action: XBaseEntityHubAction.Update.GetStringValue(), + payLoad: result.ToJSON(camelCase: true), + connectionId: connectionId + ); + } - /// - /// remove a range of exists Dtos ... - /// - /// - /// - /// - /// - /// - public async Task RemoveRangeAsync( - IEnumerable items, - bool softDelete = true, - bool saveChanges = true, - CancellationToken cancellationToken = default - ); - #endregion + // + return result; + } - // - #region Count ... /// /// count all exists Dtos ... /// @@ -161,26 +158,42 @@ namespace xPushService.Providers public async Task CountAsync( bool ignoreSoftDeleteds = true, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.CountAsync( + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } /// - /// count all exists Entities Pages by providing page size ... + /// Check a Dto exists or not ... /// - /// - /// + /// /// /// /// - public async Task PagesCountAsync( - int pageSize, - int? totalItems = null, + public async Task IsExistsAsync( + TKey id, bool ignoreSoftDeleteds = true, CancellationToken cancellationToken = default - ); - #endregion + ) + { + // + var result = await RepositoryService.IsExistsAsync( + id: id, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } - // - #region Retrieve ... /// /// retrieve an Dto by it's Id ... /// @@ -194,7 +207,19 @@ namespace xPushService.Providers bool ignoreSoftDeleteds = true, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.GetAsync( + id: id, + includeBuilder: includeBuilder, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } /// /// retrieve all exists Dtos ... @@ -209,7 +234,19 @@ namespace xPushService.Providers Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.GetAllAsync( + orderBuilder: orderBuilder, + includeBuilder: includeBuilder, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } /// /// find an Dto by providing a Conditional Expression ... @@ -224,7 +261,19 @@ namespace xPushService.Providers bool ignoreSoftDeleteds = true, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.FindOneAsync( + predicate: predicate, + includeBuilder: includeBuilder, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } /// /// find a collection of Dtos by proving a Conditional Expression ... @@ -241,7 +290,20 @@ namespace xPushService.Providers Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default - ); + ) + { + // + var result = await RepositoryService.FindManyAsync( + predicate: predicate, + orderBuilder: orderBuilder, + includeBuilder: includeBuilder, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); + + // + return result; + } /// /// retrieve Dtos based on XQuery Pagination structure ... @@ -260,24 +322,21 @@ namespace xPushService.Providers Func, IOrderedQueryable> orderBuilder = null, Func, IIncludableQueryable> includeBuilder = null, CancellationToken cancellationToken = default - ); - #endregion + ) + { + // + var result = await RepositoryService.QueryAsync( + query: query, + predicate: predicate, + orderBuilder: orderBuilder, + includeBuilder: includeBuilder, + cancellationToken: cancellationToken, + ignoreSoftDeleteds: ignoreSoftDeleteds + ); - // - #region Exists ... - /// - /// Check a Dto exists or not ... - /// - /// - /// - /// - /// - public async Task IsExistsAsync( - TKey id, - bool ignoreSoftDeleteds = true, - CancellationToken cancellationToken = default - ); - #endregion + // + return result; + } #endregion // @@ -342,8 +401,4 @@ namespace xPushService.Providers } #endregion } - - internal class XTagDto - { - } } \ No newline at end of file