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