Skip to content

Commit

Permalink
Default implementation of Bulk Operations
Browse files Browse the repository at this point in the history
- Related with #6654
  • Loading branch information
enisn committed Dec 15, 2020
1 parent 4e4b245 commit dd01731
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,42 @@ protected virtual Task SaveChangesAsync(CancellationToken cancellationToken)
{
if (UnitOfWorkManager?.Current != null)
{
return UnitOfWorkManager?.Current.SaveChangesAsync(cancellationToken);
return UnitOfWorkManager.Current.SaveChangesAsync(cancellationToken);
}

return Task.CompletedTask;
}

public abstract Task<TEntity> UpdateAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);

public virtual async Task UpdateManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
{
foreach (var entity in entities)
{
await UpdateAsync(entity, cancellationToken: cancellationToken);
}

if (autoSave)
{
await SaveChangesAsync(cancellationToken);
}
}

public abstract Task DeleteAsync(TEntity entity, bool autoSave = false, CancellationToken cancellationToken = default);

public virtual async Task DeleteManyAsync(IEnumerable<TEntity> entities, bool autoSave = false, CancellationToken cancellationToken = default)
{
foreach (var entity in entities)
{
await DeleteAsync(entity, cancellationToken: cancellationToken);
}

if (autoSave)
{
await SaveChangesAsync(cancellationToken);
}
}

public abstract Task<List<TEntity>> GetListAsync(bool includeDetails = false, CancellationToken cancellationToken = default);

public abstract Task<long> GetCountAsync(CancellationToken cancellationToken = default);
Expand Down

0 comments on commit dd01731

Please sign in to comment.