Finalized delete voice work logic.
This commit is contained in:
@@ -26,6 +26,8 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
|
|||||||
VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
|
VoiceWork[] voiceWorks = [.. dbContext.VoiceWorks.Where(voiceWork => request.VoiceWorkIds.Contains(voiceWork.VoiceWorkId))
|
||||||
.Include(x => x.Circle)];
|
.Include(x => x.Circle)];
|
||||||
|
|
||||||
|
List<VoiceWork> voiceWorksToDelete = [];
|
||||||
|
|
||||||
foreach (VoiceWork voiceWork in voiceWorks)
|
foreach (VoiceWork voiceWork in voiceWorks)
|
||||||
{
|
{
|
||||||
if (results.ContainsKey(voiceWork.VoiceWorkId) == false)
|
if (results.ContainsKey(voiceWork.VoiceWorkId) == false)
|
||||||
@@ -46,11 +48,21 @@ public class VoiceWorkWriter(AppDbContext dbContext) : IVoiceWorkWriter
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
dbContext.Remove(voiceWork);
|
voiceWorksToDelete.Add(voiceWork);
|
||||||
results[voiceWork.VoiceWorkId] = DeleteVoiceWorkStatus.Deleted;
|
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);
|
return new DeleteVoiceWorkResponse(results);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,10 +17,16 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW
|
|||||||
int voiceWorkId = 3;
|
int voiceWorkId = 3;
|
||||||
DeleteVoiceWorkRequest request = new([voiceWorkId]);
|
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);
|
DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken);
|
||||||
response.Results.Count.ShouldBe(1);
|
response.Results.Count.ShouldBe(1);
|
||||||
response.Results.ShouldContainKey(voiceWorkId);
|
response.Results.ShouldContainKey(voiceWorkId);
|
||||||
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.Deleted);
|
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.Deleted);
|
||||||
|
|
||||||
|
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
|
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -32,9 +38,15 @@ public class Delete_Voice_Work_Tests(MariaDbContainerFixture container) : VoiceW
|
|||||||
int voiceWorkId = 1;
|
int voiceWorkId = 1;
|
||||||
DeleteVoiceWorkRequest request = new([voiceWorkId]);
|
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);
|
DeleteVoiceWorkResponse response = await writer.DeleteAsync(request, TestContext.Current.CancellationToken);
|
||||||
response.Results.Count.ShouldBe(1);
|
response.Results.Count.ShouldBe(1);
|
||||||
response.Results.ShouldContainKey(voiceWorkId);
|
response.Results.ShouldContainKey(voiceWorkId);
|
||||||
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.NotAllowed);
|
response.Results[voiceWorkId].ShouldBe(DeleteVoiceWorkStatus.NotAllowed);
|
||||||
|
|
||||||
|
dbContext.VoiceWorks.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
||||||
|
dbContext.VoiceWorkSearches.FirstOrDefault(x => x.VoiceWorkId == voiceWorkId).ShouldNotBeNull();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,10 +8,10 @@
|
|||||||
|
|
||||||
<BitPivot Size="BitSize.Medium">
|
<BitPivot Size="BitSize.Medium">
|
||||||
<BitPivotItem HeaderText="@($"Available ({availableVoiceWorks?.Length ?? 0})")">
|
<BitPivotItem HeaderText="@($"Available ({availableVoiceWorks?.Length ?? 0})")">
|
||||||
<JProductCollection Products="availableVoiceWorks"></JProductCollection>
|
<JProductCollection Products="availableVoiceWorks" ProductDeleted="OnAvailableProductDeleted"></JProductCollection>
|
||||||
</BitPivotItem>
|
</BitPivotItem>
|
||||||
<BitPivotItem HeaderText="@($"Upcoming ({upcomingVoiceWorks?.Length ?? 0})")">
|
<BitPivotItem HeaderText="@($"Upcoming ({upcomingVoiceWorks?.Length ?? 0})")">
|
||||||
<JProductCollection Products="upcomingVoiceWorks"></JProductCollection>
|
<JProductCollection Products="upcomingVoiceWorks" ProductDeleted="OnUpcomingProductDeleted"></JProductCollection>
|
||||||
</BitPivotItem>
|
</BitPivotItem>
|
||||||
<BitPivotItem HeaderText="@($"Announcements ({announcedVoiceWorks?.Length ?? 0})")">
|
<BitPivotItem HeaderText="@($"Announcements ({announcedVoiceWorks?.Length ?? 0})")">
|
||||||
<JProductCollection Products="announcedVoiceWorks" ProductDeleted="OnAnnouncedProductDeleted"></JProductCollection>
|
<JProductCollection Products="announcedVoiceWorks" ProductDeleted="OnAnnouncedProductDeleted"></JProductCollection>
|
||||||
@@ -106,8 +106,20 @@
|
|||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task OnAvailableProductDeleted()
|
||||||
|
{
|
||||||
|
_ = LoadAvailableVoiceWorksAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task OnUpcomingProductDeleted()
|
||||||
|
{
|
||||||
|
_ = LoadUpcomingVoiceWorksAsync();
|
||||||
|
_ = LoadAnnouncedVoiceWorksAsync();
|
||||||
|
}
|
||||||
|
|
||||||
private async Task OnAnnouncedProductDeleted()
|
private async Task OnAnnouncedProductDeleted()
|
||||||
{
|
{
|
||||||
|
_ = LoadUpcomingVoiceWorksAsync();
|
||||||
_ = LoadAnnouncedVoiceWorksAsync();
|
_ = LoadAnnouncedVoiceWorksAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<h3>Voice Works</h3>
|
<h3>Voice Works</h3>
|
||||||
|
|
||||||
<VoiceWorkFilters Value="@State" ValueChanged="UpdateAsync" />
|
<VoiceWorkFilters Value="@State" ValueChanged="UpdateAsync" />
|
||||||
<JProductCollection Products="Result?.Items"></JProductCollection>
|
<JProductCollection Products="Result?.Items" ProductDeleted="OnProductDeleted"></JProductCollection>
|
||||||
|
|
||||||
@if (Result is not null)
|
@if (Result is not null)
|
||||||
{
|
{
|
||||||
@@ -69,4 +69,9 @@
|
|||||||
|
|
||||||
protected override Task<SearchResult<VoiceWorkSearchResult>> ExecuteSearchAsync(VoiceWorkFilterState state, CancellationToken ct)
|
protected override Task<SearchResult<VoiceWorkSearchResult>> ExecuteSearchAsync(VoiceWorkFilterState state, CancellationToken ct)
|
||||||
=> Client.SearchAsync(state.ToSearchRequest(), ct).ContinueWith(t => t.Result?.Results ?? new SearchResult<VoiceWorkSearchResult>(), ct);
|
=> Client.SearchAsync(state.ToSearchRequest(), ct).ContinueWith(t => t.Result?.Results ?? new SearchResult<VoiceWorkSearchResult>(), ct);
|
||||||
|
|
||||||
|
private async Task OnProductDeleted()
|
||||||
|
{
|
||||||
|
_ = RunSearchAsync(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -41,6 +41,19 @@ public abstract class SearchPageBase<TState, TItem> : ComponentBase, IAsyncDispo
|
|||||||
_ = RunSearchAsync();
|
_ = 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)
|
private void NavigateToState(TState next)
|
||||||
{
|
{
|
||||||
string uri = BuildUri(next);
|
string uri = BuildUri(next);
|
||||||
@@ -73,9 +86,12 @@ public abstract class SearchPageBase<TState, TItem> : ComponentBase, IAsyncDispo
|
|||||||
_ = RunSearchAsync();
|
_ = 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
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -21,10 +21,13 @@
|
|||||||
|
|
||||||
/* Buttons */
|
/* Buttons */
|
||||||
.ant-btn {
|
.ant-btn {
|
||||||
font-weight: var(--ant-button-font-weight);
|
/*font-weight: var(--ant-button-font-weight);
|
||||||
border: var(--ant-btn-border-width) var(--ant-btn-border-style) var(--ant-btn-border-color);
|
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);
|
color: var(--ant-btn-text-color);
|
||||||
background-color: var(--ant-btn-bg-color);
|
background-color: var(--ant-btn-bg-color);
|
||||||
|
border-radius: var(--ant-border-radius);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -75,6 +75,9 @@
|
|||||||
--surface-container-outline-high: rgb(83, 99, 109);
|
--surface-container-outline-high: rgb(83, 99, 109);
|
||||||
--surface-container-outline: rgb(72, 88, 99);
|
--surface-container-outline: rgb(72, 88, 99);
|
||||||
--surface-container-outline-low: rgb(63, 78, 88);
|
--surface-container-outline-low: rgb(63, 78, 88);
|
||||||
|
/* Ant Design - Core */
|
||||||
|
--ant-border-radius: 12px;
|
||||||
|
--ant-line-width: 1px;
|
||||||
/* Ant Design - Modals */
|
/* Ant Design - Modals */
|
||||||
--ant-color-text: #b4c8d6;
|
--ant-color-text: #b4c8d6;
|
||||||
--ant-modal-content-bg: #273f50;
|
--ant-modal-content-bg: #273f50;
|
||||||
|
|||||||
Reference in New Issue
Block a user