From 42fe4dee5070dfc4d9931974f2d3390133111d6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8F=20=D0=91=D0=B8=D0=B7=D1=8E=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Mon, 9 Dec 2024 14:45:33 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BB=D1=8F=20=D1=82=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D1=86=D0=B8=D0=B8=20=D0=B1=D0=BB=D0=BE=D0=BA?= =?UTF-8?q?=20try-catch=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D0=BD=D1=83=D0=B6=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repositories/ChangeLogRepository.cs | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/Persistence.Repository/Repositories/ChangeLogRepository.cs b/Persistence.Repository/Repositories/ChangeLogRepository.cs index 4b5d901..ac00e05 100644 --- a/Persistence.Repository/Repositories/ChangeLogRepository.cs +++ b/Persistence.Repository/Repositories/ChangeLogRepository.cs @@ -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> GetByDate(