forked from ddrilling/AsbCloudServer
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:
commit
c84e1ec0ea
@ -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,6 +154,7 @@ public abstract class ChangeLogRepositoryAbstract<TEntity, TDto, TRequest> : ICh
|
||||
|
||||
result += await SaveChangesWithExceptionHandling(token);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user