Compare commits
2 Commits
e78f29ffac
...
ab773f8b71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ab773f8b71 | ||
|
|
78e67796e5 |
@@ -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.Shared.Dto;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
@@ -13,6 +14,7 @@ public class GameBase : ComponentBase
|
||||
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
|
||||
|
||||
protected SelectParams<DetailOptions, object> SelectParams = default!;
|
||||
protected Select<DetailOptions, object>? SelectOption;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
@@ -40,6 +42,8 @@ public class GameBase : ComponentBase
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
SelectOption?.Close();
|
||||
}
|
||||
|
||||
private string GetDetailOptionsLabel(DetailOptions options)
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
<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">
|
||||
@Icons.Triangle
|
||||
</Select>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<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 @ref=DeletePopup Closable=false>
|
||||
|
||||
@@ -111,4 +111,9 @@ public partial class Games : GameBaseComponent
|
||||
|
||||
GameIdToUpdate = null;
|
||||
}
|
||||
private async Task HandleOnSubmitGame()
|
||||
{
|
||||
await HandleFetchDatas(false);
|
||||
await HandleFetchCategories();
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class GameBaseComponent : ComponentBase
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
private async Task HandleFetchCategories()
|
||||
protected async Task HandleFetchCategories()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
@if (Params.Headers != null)
|
||||
{
|
||||
@foreach (var header in Params.Headers.UnionBy(HeaderValues ?? [], Params.GetHeaderLabel).OrderBy(Params.GetHeaderLabel))
|
||||
@foreach (var header in (HeaderValues ?? []).UnionBy(Params.Headers, Params.GetHeaderLabel).OrderBy(Params.GetHeaderLabel))
|
||||
{
|
||||
<SelectRow IsSelected=@(HeaderValues?.Any(val => Params.GetHeaderLabel(val) == Params.GetHeaderLabel(header)))
|
||||
<SelectRow IsSelected=@(HeaderValues?.Contains(header))
|
||||
Label="@Params.GetHeaderLabel(header)" Theme=Theme
|
||||
OnClick="_ => HandleHeaderClicked(header)" />
|
||||
}
|
||||
@@ -42,9 +42,9 @@
|
||||
|
||||
@if (Params.Items != null)
|
||||
{
|
||||
@foreach (var item in Params.Items.UnionBy(Values ?? [], Params.GetItemLabel).OrderBy(Params.GetItemLabel))
|
||||
@foreach (var item in (Values ?? []).UnionBy(Params.Items, Params.GetItemLabel).OrderBy(Params.GetItemLabel))
|
||||
{
|
||||
<SelectRow IsSelected=@(Values?.Any(val => Params.GetItemLabel(val) == Params.GetItemLabel(item)))
|
||||
<SelectRow IsSelected=@(Values?.Contains(item))
|
||||
Label="@Params.GetItemLabel(item)" Theme=Theme
|
||||
OnClick="_ => HandleValueClicked(item)" />
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using GameIdeas.Shared.Exceptions;
|
||||
using GameIdeas.Shared.Model;
|
||||
using GameIdeas.WebAPI.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GameIdeas.WebAPI.Services.Games;
|
||||
|
||||
@@ -13,7 +14,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
{
|
||||
var gameToCreate = mapper.Map<Game>(gameDto);
|
||||
|
||||
HandleDeveloperPublisherCreation(gameToCreate);
|
||||
await HandleDeveloperPublisherCreation(gameToCreate);
|
||||
await context.Games.AddAsync(gameToCreate);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
@@ -35,7 +36,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
|
||||
var gameToUpdate = mapper.Map<Game>(gameDto);
|
||||
|
||||
HandleDeveloperPublisherCreation(gameToUpdate);
|
||||
await HandleDeveloperPublisherCreation(gameToUpdate);
|
||||
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
|
||||
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
|
||||
await HandleTagsCreation(gameDto.Tags, gameToUpdate.Id);
|
||||
@@ -48,12 +49,27 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
|
||||
public async Task<bool> DeleteGame(int gameId)
|
||||
{
|
||||
await HandlePlatformsCreation([], gameId);
|
||||
await HandlePropertiesCreation([], gameId);
|
||||
await HandleTagsCreation([], gameId);
|
||||
|
||||
var gameToRemove = await context.Games
|
||||
.FirstOrDefaultAsync(g => g.Id == gameId)
|
||||
?? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context");
|
||||
|
||||
context.Games.Remove(gameToRemove);
|
||||
return await context.SaveChangesAsync() != 0;
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
context.Publishers.RemoveRange(
|
||||
context.Publishers.Include(p => p.Games)
|
||||
.Where(p => p.Games.Count == 0));
|
||||
|
||||
context.Developers.RemoveRange(
|
||||
context.Developers.Include(d => d.Games)
|
||||
.Where(d => d.Games.Count == 0));
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
return true;
|
||||
}
|
||||
|
||||
private async Task HandlePlatformsCreation(IEnumerable<PlatformDto>? categoriesToCreate, int gameId)
|
||||
@@ -62,6 +78,9 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
{
|
||||
var gps = mapper.Map<ICollection<GamePlatform>>(categoriesToCreate);
|
||||
|
||||
context.GamePlatforms.RemoveRange(
|
||||
context.GamePlatforms.Where(gp => gp.GameId == gameId));
|
||||
|
||||
foreach (var gp in gps)
|
||||
{
|
||||
gp.GameId = gameId;
|
||||
@@ -69,6 +88,14 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
|
||||
context.Platforms.AttachRange(gps.Select(gp => gp.Platform));
|
||||
await context.GamePlatforms.AddRangeAsync(gps);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
context.Platforms.RemoveRange(
|
||||
context.Platforms.Include(p => p.GamePlatforms)
|
||||
.Where(p => p.GamePlatforms.Count == 0));
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +105,9 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
{
|
||||
var gps = mapper.Map<ICollection<GameProperty>>(categoriesToCreate);
|
||||
|
||||
context.GameProperties.RemoveRange(
|
||||
context.GameProperties.Where(gp => gp.GameId == gameId));
|
||||
|
||||
foreach (var gp in gps)
|
||||
{
|
||||
gp.GameId = gameId;
|
||||
@@ -85,6 +115,14 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
|
||||
context.Properties.AttachRange(gps.Select(gp => gp.Property));
|
||||
await context.GameProperties.AddRangeAsync(gps);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
context.Properties.RemoveRange(
|
||||
context.Properties.Include(p => p.GameProperties)
|
||||
.Where(p => p.GameProperties.Count == 0));
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +132,9 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
{
|
||||
var gts = mapper.Map<ICollection<GameTag>>(categoriesToCreate);
|
||||
|
||||
context.GameTags.RemoveRange(
|
||||
context.GameTags.Where(gt => gt.GameId == gameId));
|
||||
|
||||
foreach (var gt in gts)
|
||||
{
|
||||
gt.GameId = gameId;
|
||||
@@ -101,11 +142,30 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
||||
|
||||
context.Tags.AttachRange(gts.Select(gt => gt.Tag));
|
||||
await context.GameTags.AddRangeAsync(gts);
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
context.Tags.RemoveRange(
|
||||
context.Tags.Include(t => t.GameTags)
|
||||
.Where(t => t.GameTags.Count == 0));
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleDeveloperPublisherCreation(Game? game)
|
||||
private async Task HandleDeveloperPublisherCreation(Game? game)
|
||||
{
|
||||
context.Publishers.RemoveRange(
|
||||
context.Publishers.Include(p => p.Games)
|
||||
.Where(p => p.Games.Count == 0));
|
||||
|
||||
context.Developers.RemoveRange(
|
||||
context.Developers.Include(d => d.Games)
|
||||
.Where(d => d.Games.Count == 0));
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
if (game?.Publisher != null)
|
||||
{
|
||||
context.Publishers.Attach(game.Publisher);
|
||||
|
||||
Reference in New Issue
Block a user