Update and delete games #48

Merged
Egamorf merged 10 commits from feature/update-and-delete-games into main 2025-05-13 14:13:31 +02:00
6 changed files with 18 additions and 4 deletions
Showing only changes of commit ab773f8b71 - Show all commits

View File

@@ -1,4 +1,5 @@
using GameIdeas.BlazorApp.Shared.Components.Select.Models; using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources; using GameIdeas.Resources;
using GameIdeas.Shared.Dto; using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components;
@@ -13,6 +14,7 @@ public class GameBase : ComponentBase
[Inject] public NavigationManager NavigationManager { get; set; } = default!; [Inject] public NavigationManager NavigationManager { get; set; } = default!;
protected SelectParams<DetailOptions, object> SelectParams = default!; protected SelectParams<DetailOptions, object> SelectParams = default!;
protected Select<DetailOptions, object>? SelectOption;
protected override void OnInitialized() protected override void OnInitialized()
{ {
@@ -40,6 +42,8 @@ public class GameBase : ComponentBase
default: default:
break; break;
} }
SelectOption?.Close();
} }
private string GetDetailOptionsLabel(DetailOptions options) private string GetDetailOptionsLabel(DetailOptions options)

View File

@@ -35,7 +35,7 @@
<Interest Value="GameDto.Interest" /> <Interest Value="GameDto.Interest" />
<Select TItem="DetailOptions" THeader="object" Type="SelectType.Single" Theme="SelectTheme.RowOption" <Select @ref="SelectOption" TItem="DetailOptions" THeader="object" Type="SelectType.Single" Theme="SelectTheme.RowOption"
Params="SelectParams" ValuesChanged="HandlerSelectValuesChanged"> Params="SelectParams" ValuesChanged="HandlerSelectValuesChanged">
@Icons.Triangle @Icons.Triangle
</Select> </Select>

View File

@@ -42,7 +42,7 @@
</div> </div>
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false> <Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
<GameCreationForm @ref="CreationForm" Categories="Categories" OnSubmit="() => HandleFetchDatas()" OnRender="HandleRenderCreationForm" /> <GameCreationForm @ref="CreationForm" Categories="Categories" OnSubmit="HandleOnSubmitGame" OnRender="HandleRenderCreationForm" />
</Popup> </Popup>
<Popup @ref=DeletePopup Closable=false> <Popup @ref=DeletePopup Closable=false>

View File

@@ -111,4 +111,9 @@ public partial class Games : GameBaseComponent
GameIdToUpdate = null; GameIdToUpdate = null;
} }
private async Task HandleOnSubmitGame()
{
await HandleFetchDatas(false);
await HandleFetchCategories();
}
} }

View File

@@ -19,7 +19,7 @@ public class GameBaseComponent : ComponentBase
await base.OnInitializedAsync(); await base.OnInitializedAsync();
} }
private async Task HandleFetchCategories() protected async Task HandleFetchCategories()
{ {
try try
{ {

View File

@@ -89,6 +89,8 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Platforms.AttachRange(gps.Select(gp => gp.Platform)); context.Platforms.AttachRange(gps.Select(gp => gp.Platform));
await context.GamePlatforms.AddRangeAsync(gps); await context.GamePlatforms.AddRangeAsync(gps);
await context.SaveChangesAsync();
context.Platforms.RemoveRange( context.Platforms.RemoveRange(
context.Platforms.Include(p => p.GamePlatforms) context.Platforms.Include(p => p.GamePlatforms)
.Where(p => p.GamePlatforms.Count == 0)); .Where(p => p.GamePlatforms.Count == 0));
@@ -114,6 +116,8 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Properties.AttachRange(gps.Select(gp => gp.Property)); context.Properties.AttachRange(gps.Select(gp => gp.Property));
await context.GameProperties.AddRangeAsync(gps); await context.GameProperties.AddRangeAsync(gps);
await context.SaveChangesAsync();
context.Properties.RemoveRange( context.Properties.RemoveRange(
context.Properties.Include(p => p.GameProperties) context.Properties.Include(p => p.GameProperties)
.Where(p => p.GameProperties.Count == 0)); .Where(p => p.GameProperties.Count == 0));
@@ -139,6 +143,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
context.Tags.AttachRange(gts.Select(gt => gt.Tag)); context.Tags.AttachRange(gts.Select(gt => gt.Tag));
await context.GameTags.AddRangeAsync(gts); await context.GameTags.AddRangeAsync(gts);
await context.SaveChangesAsync();
context.Tags.RemoveRange( context.Tags.RemoveRange(
context.Tags.Include(t => t.GameTags) context.Tags.Include(t => t.GameTags)