Merge pull request 'Сохранение данных с возможностью отката транзакции в методе Insert в ChangeLogRepositoryAbstract' (#307) from fix/insert-process-maps-in-transaction into dev

Reviewed-on: https://test.digitaldrilling.ru:8443/DDrilling/AsbCloudServer/pulls/307
This commit is contained in:
Никита Фролов 2024-08-10 17:08:22 +05:00
commit c84e1ec0ea

View File

@ -117,6 +117,22 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
}
public async Task<int> InsertRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
using var transaction = db.Database.BeginTransaction();
try
{
var result = await InsertRangeWithoutTransaction(idUser, dtos, token);
await transaction.CommitAsync(token);
return result;
}
catch
{
await transaction.RollbackAsync(token);
throw;
}
}
private async Task<int> InsertRangeWithoutTransaction(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
{
var result = 0;
if (dtos.Any())
@ -138,7 +154,8 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
result += await SaveChangesWithExceptionHandling(token);
}
return result;
return result;
}
public async Task<int> UpdateRange(int idUser, IEnumerable<TDto> dtos, CancellationToken token)
@ -248,7 +265,7 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
try
{
result += await Clear(idUser, request, token);
result += await InsertRange(idUser, dtos, token);
result += await InsertRangeWithoutTransaction(idUser, dtos, token);
await transaction.CommitAsync(token);
return result;