Для транзакции блок try-catch больше не нужен
This commit is contained in:
parent
4ccbe4361a
commit
42fe4dee50
@ -101,34 +101,29 @@ public class ChangeLogRepository : IChangeLogRepository
|
||||
|
||||
var result = 0;
|
||||
using var transaction = await db.Database.BeginTransactionAsync(token);
|
||||
try
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
foreach (var dto in dtos)
|
||||
var updatedEntity = updatedEntities.GetValueOrDefault(dto.Id);
|
||||
if (updatedEntity is null)
|
||||
{
|
||||
var updatedEntity = updatedEntities.GetValueOrDefault(dto.Id);
|
||||
if (updatedEntity is null)
|
||||
{
|
||||
throw new ArgumentException($"Entity with id = {dto.Id} doesn't exist in Db", nameof(dto));
|
||||
}
|
||||
|
||||
var newEntity = CreateEntityFromDto(idEditor, updatedEntity.IdDiscriminator, dto);
|
||||
dbSet.Add(newEntity);
|
||||
|
||||
updatedEntity.IdNext = newEntity.Id;
|
||||
updatedEntity.Obsolete = DateTimeOffset.UtcNow;
|
||||
updatedEntity.IdEditor = idEditor;
|
||||
throw new ArgumentException($"Entity with id = {dto.Id} doesn't exist in Db", nameof(dto));
|
||||
}
|
||||
|
||||
result = await db.SaveChangesAsync(token);
|
||||
await transaction.CommitAsync(token);
|
||||
var newEntity = CreateEntityFromDto(idEditor, updatedEntity.IdDiscriminator, dto);
|
||||
dbSet.Add(newEntity);
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await transaction.RollbackAsync(token);
|
||||
throw;
|
||||
updatedEntity.IdNext = newEntity.Id;
|
||||
updatedEntity.Obsolete = DateTimeOffset.UtcNow;
|
||||
updatedEntity.IdEditor = idEditor;
|
||||
}
|
||||
|
||||
result = await db.SaveChangesAsync(token);
|
||||
await transaction.CommitAsync(token);
|
||||
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public async Task<PaginationContainer<DataWithWellDepthAndSectionDto>> GetByDate(
|
||||
|
Loading…
Reference in New Issue
Block a user