diff --git a/TournamentManager/TournamentManager/Data/GenericRepository.cs b/TournamentManager/TournamentManager/Data/GenericRepository.cs index 9fbe959..0deb94b 100644 --- a/TournamentManager/TournamentManager/Data/GenericRepository.cs +++ b/TournamentManager/TournamentManager/Data/GenericRepository.cs @@ -16,14 +16,14 @@ public GenericRepository(MultiTenancy.IDbContext dbContext) public virtual async Task SaveEntityAsync(T entityToSave, bool refetchAfterSave, bool recurse, CancellationToken cancellationToken) where T : IEntity2 { - var transactionName = Guid.NewGuid().ToString("N"); + var transactionName = string.Concat(nameof(GenericRepository), nameof(SaveEntityAsync), Guid.NewGuid().ToString("N")); using var da = _dbContext.GetNewAdapter(); try { await da.StartTransactionAsync(IsolationLevel.ReadCommitted, transactionName, cancellationToken); - var success = await da.SaveEntityAsync(entityToSave, refetchAfterSave, recurse, cancellationToken); + await da.SaveEntityAsync(entityToSave, refetchAfterSave, recurse, cancellationToken); await da.CommitAsync(cancellationToken); - return success; + return true; } catch (Exception e) { diff --git a/TournamentManager/TournamentManager/Data/MatchRepository.cs b/TournamentManager/TournamentManager/Data/MatchRepository.cs index 98b93e6..85f7870 100644 --- a/TournamentManager/TournamentManager/Data/MatchRepository.cs +++ b/TournamentManager/TournamentManager/Data/MatchRepository.cs @@ -339,7 +339,7 @@ public virtual async Task SaveMatchResultAsync(MatchEntity matchEntity, Ca try { await da.StartTransactionAsync(IsolationLevel.ReadCommitted, - string.Concat(nameof(MatchRepository), nameof(SaveMatchResultAsync), Guid.NewGuid().ToString()), cancellationToken); + string.Concat(nameof(MatchRepository), nameof(SaveMatchResultAsync), Guid.NewGuid().ToString("N")), cancellationToken); if (matchEntity.Sets.RemovedEntitiesTracker != null) { @@ -348,9 +348,9 @@ await da.StartTransactionAsync(IsolationLevel.ReadCommitted, matchEntity.Sets.RemovedEntitiesTracker = null; } - var success = await da.SaveEntityAsync(matchEntity, false, true, cancellationToken); + await da.SaveEntityAsync(matchEntity, false, true, cancellationToken); await da.CommitAsync(cancellationToken); - return success; + return true; } catch (Exception e) { @@ -378,20 +378,20 @@ public virtual async Task DeleteMatchResultAsync(long matchId, Cancellatio ?? throw new ArgumentException(@"No match found", nameof(matchId)); matchEntity.HomePoints = matchEntity.GuestPoints = null; + matchEntity.RealStart = matchEntity.RealEnd = null; matchEntity.Remarks = string.Empty; matchEntity.IsOverruled = false; matchEntity.IsComplete = false; - // Track the removed sets - matchEntity.Sets.RemovedEntitiesTracker = new EntityCollection(); - matchEntity.Sets.Clear(); - using var da = _dbContext.GetNewAdapter(); try { await da.StartTransactionAsync(IsolationLevel.ReadCommitted, - string.Concat(nameof(MatchRepository), nameof(DeleteMatchResultAsync), Guid.NewGuid().ToString()), cancellationToken); + string.Concat(nameof(MatchRepository), nameof(DeleteMatchResultAsync), Guid.NewGuid().ToString("N")), cancellationToken); + + // Track the removed sets + matchEntity.Sets.RemovedEntitiesTracker = matchEntity.Sets; // Delete the sets if (matchEntity.Sets.RemovedEntitiesTracker != null) @@ -402,9 +402,9 @@ await da.StartTransactionAsync(IsolationLevel.ReadCommitted, } // Save the changes to the match - var success = await da.SaveEntityAsync(matchEntity, false, true, cancellationToken); + await da.SaveEntityAsync(matchEntity, false, false, cancellationToken); await da.CommitAsync(cancellationToken); - return success; + return true; } catch (Exception e) { diff --git a/TournamentManager/TournamentManager/Data/RankingRepository.cs b/TournamentManager/TournamentManager/Data/RankingRepository.cs index 709cc50..1fbc1e5 100644 --- a/TournamentManager/TournamentManager/Data/RankingRepository.cs +++ b/TournamentManager/TournamentManager/Data/RankingRepository.cs @@ -31,7 +31,8 @@ public virtual async Task ReplaceAsync(RankingList rankingList, long roundId, Ca var rankingColl = new EntityCollection(new RankingEntityFactory()); using var da = _dbContext.GetNewAdapter(); - var transactionName = nameof(ReplaceAsync) + Guid.NewGuid().ToString("N"); + var transactionName = + string.Concat(nameof(RankingRepository), nameof(ReplaceAsync), Guid.NewGuid().ToString("N")); try { diff --git a/TournamentManager/TournamentManager/TournamentCreator.cs b/TournamentManager/TournamentManager/TournamentCreator.cs index 5b50378..a401d5d 100644 --- a/TournamentManager/TournamentManager/TournamentCreator.cs +++ b/TournamentManager/TournamentManager/TournamentCreator.cs @@ -2,6 +2,7 @@ using SD.LLBLGen.Pro.ORMSupportClasses; using TournamentManager.DAL.EntityClasses; using TournamentManager.DAL.HelperClasses; +using TournamentManager.Data; using TournamentManager.MultiTenancy; namespace TournamentManager; @@ -86,7 +87,7 @@ await _appDb.TournamentRepository.GetTournamentAsync( /// True, if creation was successful, false otherwise. public async Task CopyRound(long fromTournamentId, long toTournamentId, IList excludeRoundId, CancellationToken cancellationToken) { - const string transactionName = "CopyRounds"; + var transactionName = string.Concat(nameof(TournamentCreator), nameof(CopyRound), Guid.NewGuid().ToString("N")); var now = DateTime.UtcNow; // get the rounds of SOURCE tournament @@ -165,7 +166,7 @@ public async Task CopyRound(long fromTournamentId, long toTournamentId, IL public async Task SetLegDates(IEnumerable rounds , int sequenceNo, DateTime start, DateTime end, CancellationToken cancellationToken) { - const string transactionName = "SetLegDates"; + var transactionName = string.Concat(nameof(RankingRepository), nameof(SetLegDates), Guid.NewGuid().ToString("N")); var now = DateTime.UtcNow; var roundEntities = (rounds as RoundEntity[] ?? rounds.ToArray()).ToList();