diff --git a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs index 5954de7c5..554fdde25 100644 --- a/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs +++ b/WebAPI/LearningHub.Nhs.Repository/Resources/BlockCollectionRepository.cs @@ -83,10 +83,22 @@ public async Task DeleteBlockCollection(int userId, int blockCollectionId) foreach (var id in collectionIds) { - using (var lhContext = new LearningHubDbContext(this.DbContext.Options)) + _ = Task.Run(async () => { - _ = lhContext.Database.ExecuteSqlRawAsync("resources.BlockCollectionDelete @p0", new SqlParameter("@p0", SqlDbType.Int) { Value = id }); - } + var lhContext = new LearningHubDbContext(this.DbContext.Options); + try + { + await lhContext.Database.ExecuteSqlRawAsync("resources.BlockCollectionDelete @p0", new SqlParameter("@p0", SqlDbType.Int) { Value = id }); + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + finally + { + await lhContext.DisposeAsync(); + } + }); } }