Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Refactor delete logic in Repository

supportba755ab353f8
diff --git a/src/Business/Grand.Business.Customers/Services/CustomerService.cs b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
index e0a0899f1..7844c29e9 100644
--- a/src/Business/Grand.Business.Customers/Services/CustomerService.cs
+++ b/src/Business/Grand.Business.Customers/Services/CustomerService.cs
@@ -609,9 +609,9 @@ public class CustomerService : ICustomerService
query = query.Where(x => !x.IsSystemAccount);
- var customers = await _customerRepository.DeleteAsync(query);
-
- return customers.Count();
+ var count = query.Count();
+ await _customerRepository.DeleteAsync(query);
+ return count;
}
#endregion
diff --git a/src/Core/Grand.Data/IRepository.cs b/src/Core/Grand.Data/IRepository.cs
index 3634f3606..05c7bec12 100644
--- a/src/Core/Grand.Data/IRepository.cs
+++ b/src/Core/Grand.Data/IRepository.cs
@@ -189,14 +189,14 @@ public interface IRepository<T> where T : BaseEntity
/// Async Delete entities
/// </summary>
/// <param name="entities">Entities</param>
- Task<IEnumerable<T>> DeleteAsync(IEnumerable<T> entities);
+ Task DeleteAsync(IEnumerable<T> entities);
/// <summary>
/// Delete a many entities
/// </summary>
- /// <param name="filterexpression"></param>
+ /// <param name="filterExpression"></param>
/// <returns></returns>
- Task DeleteManyAsync(Expression<Func<T, bool>> filterexpression);
+ Task DeleteManyAsync(Expression<Func<T, bool>> filterExpression);
/// <summary>
/// Clear entities
diff --git a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
index f5b7d99c8..3a852c48f 100644
--- a/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
+++ b/src/Core/Grand.Data/LiteDb/LiteDBRepository.cs
@@ -532,20 +532,19 @@ public class LiteDBRepository<T> : IRepository<T> where T : BaseEntity
/// Async Delete entities
/// </summary>
/// <param name="entities">Entities</param>
- public virtual async Task<IEnumerable<T>> DeleteAsync(IEnumerable<T> entities)
+ public virtual async Task DeleteAsync(IEnumerable<T> entities)
{
foreach (var entity in entities) await DeleteAsync(entity);
- return entities;
}
/// <summary>
/// Delete a many entities
/// </summary>
- /// <param name="filterexpression"></param>
+ /// <param name="filterExpression"></param>
/// <returns></returns>
- public virtual Task DeleteManyAsync(Expression<Func<T, bool>> filterexpression)
+ public virtual Task DeleteManyAsync(Expression<Func<T, bool>> filterExpression)
{
- _collection.DeleteMany(filterexpression);
+ _collection.DeleteMany(filterExpression);
return Task.CompletedTask;
}
diff --git a/src/Core/Grand.Data/Mongo/MongoRepository.cs b/src/Core/Grand.Data/Mongo/MongoRepository.cs
index a6edc0399..bd7c2062d 100644
--- a/src/Core/Grand.Data/Mongo/MongoRepository.cs
+++ b/src/Core/Grand.Data/Mongo/MongoRepository.cs
@@ -408,21 +408,19 @@ public class MongoRepository<T> : IRepository<T> where T : BaseEntity
/// Async Delete entities
/// </summary>
/// <param name="entities">Entities</param>
- public virtual async Task<IEnumerable<T>> DeleteAsync(IEnumerable<T> entities)
+ public virtual async Task DeleteAsync(IEnumerable<T> entities)
{
foreach (var entity in entities) await DeleteAsync(entity);
-
- return entities;
}
/// <summary>
/// Delete a many entities
/// </summary>
- /// <param name="filterexpression"></param>
+ /// <param name="filterExpression"></param>
/// <returns></returns>
- public virtual async Task DeleteManyAsync(Expression<Func<T, bool>> filterexpression)
+ public virtual async Task DeleteManyAsync(Expression<Func<T, bool>> filterExpression)
{
- await _collection.DeleteManyAsync(filterexpression);
+ await _collection.DeleteManyAsync(filterExpression);
}
/// <summary>