diff --git a/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs b/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs index bc85128..ed13953 100644 --- a/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs +++ b/JSMR.Infrastructure/Data/Repositories/VoiceWorks/VoiceWorkWriter.cs @@ -26,6 +26,8 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId)) .Include(x => x.Circle)]; + List voiceWorksToDelete = []; + foreach (VoiceWork voiceWork in voiceWorks) { if (results.ContainsKey(voiceWork.VoiceWorkId) == false) @@ -46,11 +48,21 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter continue; } - dbContext.Remove(voiceWork); + voiceWorksToDelete.Add(voiceWork); results[voiceWork.VoiceWorkId] = DeleteVoiceWorkStatus.Deleted; } - await dbContext.SaveChangesAsync(cancellationToken); + int[] voiceWorkIdsToDelete = [.. voiceWorksToDelete.Select(x => x.VoiceWorkId)]; + + if (voiceWorkIdsToDelete.Length > 0) + { + dbContext.VoiceWorks.RemoveRange(voiceWorksToDelete); + await dbContext.SaveChangesAsync(cancellationToken); + + await dbContext.VoiceWorkSearches + .Where(x => voiceWorkIdsToDelete.Contains(x.VoiceWorkId)) + .ExecuteDeleteAsync(cancellationToken); + } return new DeleteVoiceWorkResponse(results); } diff --git a/JSMR.Tests/Data/Repositories/VoiceWorks/Delete_Voice_Work_Tests.cs b/JSMR.Tests/Data/Repositories/VoiceWorks/Delete_Voice_Work_Tests.cs index 4401538..45a248e 100644 --- a/JSMR.Tests/Data/Repositories/VoiceWorks/Delete_Voice_Work_Tests.cs +++ b/JSMR.Tests/Data/Repositories/VoiceWorks/Delete_Voice_Work_Tests.cs @@ -17,10 +17,16 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW int voiceWorkId = 3; DeleteVoiceWorkRequest request = new([voiceWorkId]); + dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); + dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); + DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken); response.Results.Count.ShouldBe(1); response.Results.ShouldContainKey(voiceWorkId); response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.Deleted); + + dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull(); + dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull(); } [Fact] @@ -32,9 +38,15 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW int voiceWorkId = 1; DeleteVoiceWorkRequest request = new([voiceWorkId]); + dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); + dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); + DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken); response.Results.Count.ShouldBe(1); response.Results.ShouldContainKey(voiceWorkId); response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.NotAllowed); + + dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); + dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull(); } } \ No newline at end of file diff --git a/JSMR.UI.Blazor/Pages/Home.razor b/JSMR.UI.Blazor/Pages/Home.razor index e070e0e..b6a27a3 100644 --- a/JSMR.UI.Blazor/Pages/Home.razor +++ b/JSMR.UI.Blazor/Pages/Home.razor @@ -8,10 +8,10 @@ - + - + @@ -106,8 +106,20 @@ await InvokeAsync(StateHasChanged); } + private async Task OnAvailableProductDeleted() + { + _ = LoadAvailableVoiceWorksAsync(); + } + + private async Task OnUpcomingProductDeleted() + { + _ = LoadUpcomingVoiceWorksAsync(); + _ = LoadAnnouncedVoiceWorksAsync(); + } + private async Task OnAnnouncedProductDeleted() { + _ = LoadUpcomingVoiceWorksAsync(); _ = LoadAnnouncedVoiceWorksAsync(); } } \ No newline at end of file diff --git a/JSMR.UI.Blazor/Pages/VoiceWorks.razor b/JSMR.UI.Blazor/Pages/VoiceWorks.razor index 716b77c..5ba50d0 100644 --- a/JSMR.UI.Blazor/Pages/VoiceWorks.razor +++ b/JSMR.UI.Blazor/Pages/VoiceWorks.razor @@ -17,7 +17,7 @@

Voice Works

- + @if (Result is not null) { @@ -69,4 +69,9 @@ protected override Task> ExecuteSearchAsync(VoiceWorkFilterState state, CancellationToken ct) => Client.SearchAsync(state.ToSearchRequest(), ct).ContinueWith(t => t.Result?.Results ?? new SearchResult(), ct); + + private async Task OnProductDeleted() + { + _ = RunSearchAsync(false); + } } \ No newline at end of file diff --git a/JSMR.UI.Blazor/Shared/SearchPageBase.cs b/JSMR.UI.Blazor/Shared/SearchPageBase.cs index a7dae14..01b933b 100644 --- a/JSMR.UI.Blazor/Shared/SearchPageBase.cs +++ b/JSMR.UI.Blazor/Shared/SearchPageBase.cs @@ -41,6 +41,19 @@ public abstract class SearchPageBase : ComponentBase, IAsyncDispo _ = RunSearchAsync(); } + //protected async Task Update2Async(TState next, bool scrollToTop) + //{ + // if (Equals(next, State)) + // return; + + // Console.WriteLine("Got here"); + + // State = next; + // NavigateToState(next); + + // _ = RunSearchAsync(scrollToTop); + //} + private void NavigateToState(TState next) { string uri = BuildUri(next); @@ -73,9 +86,12 @@ public abstract class SearchPageBase : ComponentBase, IAsyncDispo _ = RunSearchAsync(); } - private async Task RunSearchAsync() + protected async Task RunSearchAsync(bool scrollTotop = true) { - await JS.InvokeVoidAsync("pageHelpers.scrollToTop"); + if (scrollTotop) + await JS.InvokeVoidAsync("pageHelpers.scrollToTop"); + + Console.WriteLine("Got here 2"); try { diff --git a/JSMR.UI.Blazor/wwwroot/css/ant-design.css b/JSMR.UI.Blazor/wwwroot/css/ant-design.css index 8ae7838..55f5313 100644 --- a/JSMR.UI.Blazor/wwwroot/css/ant-design.css +++ b/JSMR.UI.Blazor/wwwroot/css/ant-design.css @@ -21,10 +21,13 @@ /* Buttons */ .ant-btn { - font-weight: var(--ant-button-font-weight); - border: var(--ant-btn-border-width) var(--ant-btn-border-style) var(--ant-btn-border-color); + /*font-weight: var(--ant-button-font-weight); + border-width: var(--ant-btn-border-width); + border-style: var(--ant-btn-border-style); + border-color: var(--ant-btn-border-color); color: var(--ant-btn-text-color); background-color: var(--ant-btn-bg-color); + border-radius: var(--ant-border-radius);*/ } /* diff --git a/JSMR.UI.Blazor/wwwroot/css/theme-frozen.css b/JSMR.UI.Blazor/wwwroot/css/theme-frozen.css index 776a4ae..ef299f5 100644 --- a/JSMR.UI.Blazor/wwwroot/css/theme-frozen.css +++ b/JSMR.UI.Blazor/wwwroot/css/theme-frozen.css @@ -75,6 +75,9 @@ --surface-container-outline-high: rgb(83, 99, 109); --surface-container-outline: rgb(72, 88, 99); --surface-container-outline-low: rgb(63, 78, 88); + /* Ant Design - Core */ + --ant-border-radius: 12px; + --ant-line-width: 1px; /* Ant Design - Modals */ --ant-color-text: #b4c8d6; --ant-modal-content-bg: #273f50;