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.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)
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -111,4 +111,9 @@ public partial class Games : GameBaseComponent
|
|||||||
|
|
||||||
GameIdToUpdate = null;
|
GameIdToUpdate = null;
|
||||||
}
|
}
|
||||||
|
private async Task HandleOnSubmitGame()
|
||||||
|
{
|
||||||
|
await HandleFetchDatas(false);
|
||||||
|
await HandleFetchCategories();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ public class GameBaseComponent : ComponentBase
|
|||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task HandleFetchCategories()
|
protected async Task HandleFetchCategories()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
@if (Params.Headers != null)
|
@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
|
Label="@Params.GetHeaderLabel(header)" Theme=Theme
|
||||||
OnClick="_ => HandleHeaderClicked(header)" />
|
OnClick="_ => HandleHeaderClicked(header)" />
|
||||||
}
|
}
|
||||||
@@ -42,9 +42,9 @@
|
|||||||
|
|
||||||
@if (Params.Items != null)
|
@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
|
Label="@Params.GetItemLabel(item)" Theme=Theme
|
||||||
OnClick="_ => HandleValueClicked(item)" />
|
OnClick="_ => HandleValueClicked(item)" />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using GameIdeas.Shared.Exceptions;
|
|||||||
using GameIdeas.Shared.Model;
|
using GameIdeas.Shared.Model;
|
||||||
using GameIdeas.WebAPI.Context;
|
using GameIdeas.WebAPI.Context;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace GameIdeas.WebAPI.Services.Games;
|
namespace GameIdeas.WebAPI.Services.Games;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
|||||||
{
|
{
|
||||||
var gameToCreate = mapper.Map<Game>(gameDto);
|
var gameToCreate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
HandleDeveloperPublisherCreation(gameToCreate);
|
await HandleDeveloperPublisherCreation(gameToCreate);
|
||||||
await context.Games.AddAsync(gameToCreate);
|
await context.Games.AddAsync(gameToCreate);
|
||||||
await context.SaveChangesAsync();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ public class GameWriteService(GameIdeasContext context, IMapper mapper) : IGameW
|
|||||||
|
|
||||||
var gameToUpdate = mapper.Map<Game>(gameDto);
|
var gameToUpdate = mapper.Map<Game>(gameDto);
|
||||||
|
|
||||||
HandleDeveloperPublisherCreation(gameToUpdate);
|
await HandleDeveloperPublisherCreation(gameToUpdate);
|
||||||
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
|
await HandlePlatformsCreation(gameDto.Platforms, gameToUpdate.Id);
|
||||||
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
|
await HandlePropertiesCreation(gameDto.Properties, gameToUpdate.Id);
|
||||||
await HandleTagsCreation(gameDto.Tags, 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)
|
public async Task<bool> DeleteGame(int gameId)
|
||||||
{
|
{
|
||||||
|
await HandlePlatformsCreation([], gameId);
|
||||||
|
await HandlePropertiesCreation([], gameId);
|
||||||
|
await HandleTagsCreation([], gameId);
|
||||||
|
|
||||||
var gameToRemove = await context.Games
|
var gameToRemove = await context.Games
|
||||||
.FirstOrDefaultAsync(g => g.Id == gameId)
|
.FirstOrDefaultAsync(g => g.Id == gameId)
|
||||||
?? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context");
|
?? throw new NotFoundException($"[{typeof(Game).FullName}] with ID {gameId} has not been found in context");
|
||||||
|
|
||||||
context.Games.Remove(gameToRemove);
|
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)
|
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);
|
var gps = mapper.Map<ICollection<GamePlatform>>(categoriesToCreate);
|
||||||
|
|
||||||
|
context.GamePlatforms.RemoveRange(
|
||||||
|
context.GamePlatforms.Where(gp => gp.GameId == gameId));
|
||||||
|
|
||||||
foreach (var gp in gps)
|
foreach (var gp in gps)
|
||||||
{
|
{
|
||||||
gp.GameId = gameId;
|
gp.GameId = gameId;
|
||||||
@@ -69,6 +88,14 @@ 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.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);
|
var gps = mapper.Map<ICollection<GameProperty>>(categoriesToCreate);
|
||||||
|
|
||||||
|
context.GameProperties.RemoveRange(
|
||||||
|
context.GameProperties.Where(gp => gp.GameId == gameId));
|
||||||
|
|
||||||
foreach (var gp in gps)
|
foreach (var gp in gps)
|
||||||
{
|
{
|
||||||
gp.GameId = gameId;
|
gp.GameId = gameId;
|
||||||
@@ -85,6 +115,14 @@ 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.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);
|
var gts = mapper.Map<ICollection<GameTag>>(categoriesToCreate);
|
||||||
|
|
||||||
|
context.GameTags.RemoveRange(
|
||||||
|
context.GameTags.Where(gt => gt.GameId == gameId));
|
||||||
|
|
||||||
foreach (var gt in gts)
|
foreach (var gt in gts)
|
||||||
{
|
{
|
||||||
gt.GameId = gameId;
|
gt.GameId = gameId;
|
||||||
@@ -101,11 +142,30 @@ 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.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)
|
if (game?.Publisher != null)
|
||||||
{
|
{
|
||||||
context.Publishers.Attach(game.Publisher);
|
context.Publishers.Attach(game.Publisher);
|
||||||
|
|||||||
Reference in New Issue
Block a user