Update and delete games (#48)
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m27s
All checks were successful
Game Ideas deploy / build-test-deploy (push) Successful in 1m27s
Co-authored-by: Maxime Adler <madler@sqli.com> Reviewed-on: #48
This commit was merged in pull request #48.
This commit is contained in:
@@ -20,6 +20,20 @@ public static class GameHelper
|
|||||||
game.CreationDate = DateTime.Now;
|
game.CreationDate = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void UpdateTrackingDto(GameDetailDto game, AuthenticationState authState)
|
||||||
|
{
|
||||||
|
if (authState == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(authState), "Authentication state missing");
|
||||||
|
}
|
||||||
|
|
||||||
|
var userId = authState.User.FindFirstValue(ClaimTypes.Sid)
|
||||||
|
?? throw new ArgumentNullException(nameof(authState), "user state missing");
|
||||||
|
|
||||||
|
game.ModificationUserId = userId;
|
||||||
|
game.ModificationDate = DateTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetInterestColor(int interest, int maxInterest)
|
public static string GetInterestColor(int interest, int maxInterest)
|
||||||
{
|
{
|
||||||
int firstTier = (int)Math.Floor(0.33 * maxInterest);
|
int firstTier = (int)Math.Floor(0.33 * maxInterest);
|
||||||
|
|||||||
@@ -1,14 +1,22 @@
|
|||||||
@page "/Detail/{GameId:int}"
|
@page "/Detail/{GameId:int}"
|
||||||
@using GameIdeas.BlazorApp.Helpers
|
@using GameIdeas.BlazorApp.Helpers
|
||||||
|
@using GameIdeas.BlazorApp.Pages.Games.Components
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Header
|
@using GameIdeas.BlazorApp.Shared.Components.Header
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Interest
|
@using GameIdeas.BlazorApp.Shared.Components.Interest
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.Popup
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.ReadMore
|
@using GameIdeas.BlazorApp.Shared.Components.ReadMore
|
||||||
@using GameIdeas.BlazorApp.Shared.Constants
|
@using GameIdeas.BlazorApp.Shared.Constants
|
||||||
@using GameIdeas.Shared.Constants
|
@using GameIdeas.Shared.Constants
|
||||||
|
|
||||||
|
@inherits GameBaseComponent
|
||||||
@layout MainLayout
|
@layout MainLayout
|
||||||
|
|
||||||
<HeaderGameIdeas>
|
<HeaderGameIdeas>
|
||||||
|
<div class="button">
|
||||||
|
<ButtonAdd AddTypeChanged="HandleAddClicked" />
|
||||||
|
</div>
|
||||||
</HeaderGameIdeas>
|
</HeaderGameIdeas>
|
||||||
|
|
||||||
<div class="detail-container">
|
<div class="detail-container">
|
||||||
@@ -98,3 +106,7 @@
|
|||||||
<div class="section">
|
<div class="section">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
||||||
|
<GameCreationForm Categories="Categories" OnSubmit="HandleSubmitNewGame" />
|
||||||
|
</Popup>
|
||||||
@@ -1,19 +1,45 @@
|
|||||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
using GameIdeas.BlazorApp.Shared.Components;
|
||||||
|
using GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Detail;
|
namespace GameIdeas.BlazorApp.Pages.Detail;
|
||||||
|
|
||||||
public partial class GameDetail
|
public partial class GameDetail : GameBaseComponent
|
||||||
{
|
{
|
||||||
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
[Inject] private NavigationManager NavigationManager { get; set; } = default!;
|
||||||
[Parameter] public int GameId { get; set; }
|
[Parameter] public int GameId { get; set; }
|
||||||
|
|
||||||
private GameDetailDto Game = new();
|
private GameDetailDto Game = new();
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
Game = await GameGateway.GetGameById(GameId);
|
await FetchGameDetail();
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void HandleSubmitNewGame()
|
||||||
|
{
|
||||||
|
NavigationManager.NavigateTo("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task FetchGameDetail()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
Game = await GameGateway.GetGameById(GameId);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new FetchGameDetailException(ResourcesKey.ErrorFetchDetail);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,13 @@
|
|||||||
background: var(--input-selected);
|
background: var(--input-selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (min-width: 700px) and (max-width: 1000px) {
|
.button {
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
justify-content: end;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 1000px) {
|
||||||
.section {
|
.section {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||||
|
|
||||||
|
public enum DetailOptions
|
||||||
|
{
|
||||||
|
Detail,
|
||||||
|
Edit,
|
||||||
|
Delete
|
||||||
|
}
|
||||||
@@ -1,4 +1,7 @@
|
|||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.BlazorApp.Shared.Components.Select;
|
||||||
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
|
using GameIdeas.Resources;
|
||||||
|
using GameIdeas.Shared.Dto;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
||||||
@@ -6,10 +9,51 @@ namespace GameIdeas.BlazorApp.Pages.Games.Components;
|
|||||||
public class GameBase : ComponentBase
|
public class GameBase : ComponentBase
|
||||||
{
|
{
|
||||||
[Parameter] public GameDto GameDto { get; set; } = new();
|
[Parameter] public GameDto GameDto { get; set; } = new();
|
||||||
|
[Parameter] public EventCallback<GameDto> OnDelete { get; set; } = new();
|
||||||
|
[Parameter] public EventCallback<GameDto> OnEdit { get; set; } = new();
|
||||||
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
|
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
|
||||||
|
|
||||||
protected void HandleDetailClicked()
|
protected SelectParams<DetailOptions, object> SelectParams = default!;
|
||||||
|
protected Select<DetailOptions, object>? SelectOption;
|
||||||
|
|
||||||
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
NavigationManager.NavigateTo($"/Games/Detail/{GameDto.Id}");
|
SelectParams = new()
|
||||||
|
{
|
||||||
|
Items = [DetailOptions.Detail, DetailOptions.Edit, DetailOptions.Delete],
|
||||||
|
GetItemLabel = GetDetailOptionsLabel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task HandlerSelectValuesChanged(IEnumerable<DetailOptions> detailOptions)
|
||||||
|
{
|
||||||
|
var option = detailOptions.First();
|
||||||
|
switch (option)
|
||||||
|
{
|
||||||
|
case DetailOptions.Detail:
|
||||||
|
NavigationManager.NavigateTo($"/Detail/{GameDto.Id}");
|
||||||
|
break;
|
||||||
|
case DetailOptions.Edit:
|
||||||
|
await OnEdit.InvokeAsync(GameDto);
|
||||||
|
break;
|
||||||
|
case DetailOptions.Delete:
|
||||||
|
await OnDelete.InvokeAsync(GameDto);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectOption?.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetDetailOptionsLabel(DetailOptions options)
|
||||||
|
{
|
||||||
|
return options switch
|
||||||
|
{
|
||||||
|
DetailOptions.Detail => ResourcesKey.Detail,
|
||||||
|
DetailOptions.Edit => ResourcesKey.Edit,
|
||||||
|
DetailOptions.Delete => ResourcesKey.Delete,
|
||||||
|
_ => ResourcesKey.Unknown
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div id="first-label" class="label">@ResourcesKey.Title :</div>
|
<div id="first-label" class="label">@ResourcesKey.Title :</div>
|
||||||
<InputText class="title" @bind-Value=GameDto.Title/>
|
<InputText class="title" @bind-Value=GameDto.Title/>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
<div class="label">@ResourcesKey.ReleaseDate :</div>
|
||||||
@@ -24,13 +24,13 @@
|
|||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.Developer :</div>
|
<div class="label">@ResourcesKey.Developer :</div>
|
||||||
<SelectSearch TItem="DeveloperDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
|
<SelectSearch TItem="DeveloperDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
|
||||||
Items="Categories?.Developers" ValuesChanged="HandleDeveloperChanged"
|
Items="Categories?.Developers" ValuesChanged="HandleDeveloperChanged" Values="@(GameDto.Developer != null ? [GameDto.Developer] : [])"
|
||||||
AddItem="@(str => new DeveloperDto() { Name = str })" SelectType="SelectType.Single" />
|
AddItem="@(str => new DeveloperDto() { Name = str })" SelectType="SelectType.Single" />
|
||||||
</div>
|
</div>
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.Publisher :</div>
|
<div class="label">@ResourcesKey.Publisher :</div>
|
||||||
<SelectSearch TItem="PublisherDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
|
<SelectSearch TItem="PublisherDto" Theme="Theme" GetLabel="@(i => i.Name)" QuickAdd=true
|
||||||
Items="Categories?.Publishers" ValuesChanged="HandlePublisherChanged"
|
Items="Categories?.Publishers" ValuesChanged="HandlePublisherChanged" Values="@(GameDto.Publisher != null ? [GameDto.Publisher] : [])"
|
||||||
AddItem="@(str => new PublisherDto() { Name = str })" SelectType="SelectType.Single" />
|
AddItem="@(str => new PublisherDto() { Name = str })" SelectType="SelectType.Single" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -44,21 +44,21 @@
|
|||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.Properties :</div>
|
<div class="label">@ResourcesKey.Properties :</div>
|
||||||
<SelectSearch TItem="PropertyDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
<SelectSearch TItem="PropertyDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
||||||
Items="Categories?.Properties" @bind-Values=GameDto.Properties
|
Items="Categories?.Properties" @bind-Values=GameDto.Properties
|
||||||
AddItem="@(str => new PropertyDto() { Label = str })" />
|
AddItem="@(str => new PropertyDto() { Label = str })" />
|
||||||
</div>
|
</div>
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.Tags :</div>
|
<div class="label">@ResourcesKey.Tags :</div>
|
||||||
<SelectSearch TItem="TagDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
<SelectSearch TItem="TagDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
||||||
Items="Categories?.Tags" @bind-Values=GameDto.Tags
|
Items="Categories?.Tags" @bind-Values=GameDto.Tags
|
||||||
AddItem="@(str => new TagDto() { Label = str })" />
|
AddItem="@(str => new TagDto() { Label = str })" />
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="input-game">
|
<div class="input-game">
|
||||||
<div class="label">@ResourcesKey.Platforms :</div>
|
<div class="label">@ResourcesKey.Platforms :</div>
|
||||||
<SelectSearch TItem="PlatformDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
<SelectSearch TItem="PlatformDto" Theme="Theme" GetLabel="@(i => i.Label)" QuickAdd=true
|
||||||
Items="Categories?.Platforms" @bind-Values=GameDto.Platforms
|
Items="Categories?.Platforms" @bind-Values=GameDto.Platforms
|
||||||
AddItem="@(str => new PlatformDto() { Label = str })" />
|
AddItem="@(str => new PlatformDto() { Label = str })" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@foreach (var platform in GameDto.Platforms ?? [])
|
@foreach (var platform in GameDto.Platforms ?? [])
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
|||||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.Slider;
|
using GameIdeas.BlazorApp.Shared.Components.Slider;
|
||||||
|
using GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
using GameIdeas.Resources;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using Microsoft.AspNetCore.Components;
|
using Microsoft.AspNetCore.Components;
|
||||||
using Microsoft.AspNetCore.Components.Authorization;
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
@@ -19,22 +21,27 @@ public partial class GameCreationForm
|
|||||||
[CascadingParameter] private Popup? Popup { get; set; }
|
[CascadingParameter] private Popup? Popup { get; set; }
|
||||||
[Parameter] public CategoriesDto? Categories { get; set; }
|
[Parameter] public CategoriesDto? Categories { get; set; }
|
||||||
[Parameter] public EventCallback OnSubmit { get; set; }
|
[Parameter] public EventCallback OnSubmit { get; set; }
|
||||||
|
[Parameter] public EventCallback OnRender { get; set; }
|
||||||
|
|
||||||
private readonly GameDetailDto GameDto = new();
|
private GameDetailDto GameDto = new();
|
||||||
private EditContext? EditContext;
|
private EditContext? EditContext;
|
||||||
private readonly SelectTheme Theme = SelectTheme.Creation;
|
private readonly SelectTheme Theme = SelectTheme.Creation;
|
||||||
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
|
private readonly SliderParams SliderParams = new() { Gap = 1, Min = 1, Max = 5 };
|
||||||
private bool IsLoading = false;
|
private bool IsLoading = false;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override void OnInitialized()
|
||||||
{
|
{
|
||||||
EditContext = new(GameDto);
|
EditContext = new(GameDto);
|
||||||
await base.OnInitializedAsync();
|
base.OnInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||||
{
|
{
|
||||||
await Js.InvokeVoidAsync("resizeGameForm");
|
await Js.InvokeVoidAsync("resizeGameForm");
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
await OnRender.InvokeAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleOnCancel()
|
private void HandleOnCancel()
|
||||||
@@ -53,15 +60,22 @@ public partial class GameCreationForm
|
|||||||
{
|
{
|
||||||
IsLoading = true;
|
IsLoading = true;
|
||||||
|
|
||||||
|
int gameId;
|
||||||
var authState = await AuthenticationState.GetAuthenticationStateAsync();
|
var authState = await AuthenticationState.GetAuthenticationStateAsync();
|
||||||
GameHelper.WriteTrackingDto(GameDto, authState);
|
GameHelper.WriteTrackingDto(GameDto, authState);
|
||||||
|
|
||||||
var gameId = await GameGateway.CreateGame(GameDto);
|
if (GameDto.Id != null)
|
||||||
|
|
||||||
if (gameId != 0)
|
|
||||||
{
|
{
|
||||||
Popup?.Close();
|
gameId = await GameGateway.UpdateGame(GameDto);
|
||||||
await OnSubmit.InvokeAsync();
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gameId = await GameGateway.CreateGame(GameDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (gameId == 0)
|
||||||
|
{
|
||||||
|
throw new GameCreationException(ResourcesKey.ErrorCreateGame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -73,13 +87,40 @@ public partial class GameCreationForm
|
|||||||
IsLoading = false;
|
IsLoading = false;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Popup?.Close();
|
||||||
|
|
||||||
|
await OnSubmit.InvokeAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandlePublisherChanged(List<PublisherDto> pubs)
|
private void HandlePublisherChanged(List<PublisherDto> pubs)
|
||||||
{
|
{
|
||||||
GameDto.Publisher = pubs.FirstOrDefault();
|
GameDto.Publisher = pubs.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleDeveloperChanged(List<DeveloperDto> devs)
|
private void HandleDeveloperChanged(List<DeveloperDto> devs)
|
||||||
{
|
{
|
||||||
GameDto.Developer = devs.FirstOrDefault();
|
GameDto.Developer = devs.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SetGameToUpdateAsync(int gameId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
GameDto = await GameGateway.GetGameById(gameId);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new FetchGameDetailException(ResourcesKey.ErrorFetchDetail);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
EditContext = new(GameDto);
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -118,3 +118,20 @@
|
|||||||
.buttons button:hover {
|
.buttons button:hover {
|
||||||
background: var(--violet-selected);
|
background: var(--violet-selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 400px) {
|
||||||
|
.input-game {
|
||||||
|
grid-template-columns: auto 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#label-description {
|
||||||
|
width: auto !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 700px) {
|
||||||
|
.game-form {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
@using GameIdeas.BlazorApp.Helpers
|
@using GameIdeas.BlazorApp.Helpers
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Interest
|
@using GameIdeas.BlazorApp.Shared.Components.Interest
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.Select
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.Select.Models
|
||||||
@using GameIdeas.BlazorApp.Shared.Constants
|
@using GameIdeas.BlazorApp.Shared.Constants
|
||||||
@inherits GameBase
|
@inherits GameBase
|
||||||
|
|
||||||
@@ -33,5 +35,8 @@
|
|||||||
|
|
||||||
<Interest Value="GameDto.Interest" />
|
<Interest Value="GameDto.Interest" />
|
||||||
|
|
||||||
<button class="detail">@Icons.Triangle</button>
|
<Select @ref="SelectOption" TItem="DetailOptions" THeader="object" Type="SelectType.Single" Theme="SelectTheme.RowOption"
|
||||||
|
Params="SelectParams" ValuesChanged="HandlerSelectValuesChanged">
|
||||||
|
@Icons.Triangle
|
||||||
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
box-shadow: var(--drop-shadow);
|
box-shadow: var(--drop-shadow);
|
||||||
border-radius: var(--big-radius);
|
border-radius: var(--big-radius);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
overflow: hidden;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.row > * {
|
.row > * {
|
||||||
@@ -69,17 +68,23 @@
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail {
|
::deep .button {
|
||||||
transform: scale(0.6, 1) rotate(-90deg);
|
width: fit-content;
|
||||||
background: none;
|
transform: rotate(-90deg);
|
||||||
border: none;
|
transition: transform 0.2s ease-in-out;
|
||||||
outline: none;
|
justify-self: center;
|
||||||
cursor: pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
::deep .detail svg {
|
::deep .button svg {
|
||||||
fill: var(--white);
|
fill: var(--white);
|
||||||
}
|
height: 20px;
|
||||||
|
width: 20px;
|
||||||
|
transform: scale(1, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
::deep .button:hover, ::deep .button.selected {
|
||||||
|
transform: translate(-4px, 2px);
|
||||||
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 700px) {
|
@media screen and (max-width: 700px) {
|
||||||
.release-date, .tags, .storage {
|
.release-date, .tags, .storage {
|
||||||
|
|||||||
@@ -5,8 +5,9 @@
|
|||||||
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
|
@using GameIdeas.BlazorApp.Shared.Components.ButtonAdd
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Header
|
@using GameIdeas.BlazorApp.Shared.Components.Header
|
||||||
@using GameIdeas.BlazorApp.Shared.Components.Popup
|
@using GameIdeas.BlazorApp.Shared.Components.Popup
|
||||||
|
@using GameIdeas.BlazorApp.Shared.Components.Popup.Components
|
||||||
@using GameIdeas.Resources
|
@using GameIdeas.Resources
|
||||||
|
@inherits GameBaseComponent
|
||||||
@layout MainLayout
|
@layout MainLayout
|
||||||
|
|
||||||
<PageTitle>@ResourcesKey.GamesIdeas</PageTitle>
|
<PageTitle>@ResourcesKey.GamesIdeas</PageTitle>
|
||||||
@@ -24,7 +25,7 @@
|
|||||||
{
|
{
|
||||||
@foreach (var game in GamesDto)
|
@foreach (var game in GamesDto)
|
||||||
{
|
{
|
||||||
<GameRow GameDto="game" />
|
<GameRow GameDto="game" OnDelete="HandleDeleteGame" OnEdit="HandleEditGame" />
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -41,5 +42,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
<Popup @ref=ManualAddPopup BackdropFilterClicked="HandleBackdropManualAddClicked" Closable=false>
|
||||||
<GameCreationForm Categories="Categories" OnSubmit="() => HandleFetchDatas()" />
|
<GameCreationForm @ref="CreationForm" Categories="Categories" OnSubmit="HandleOnSubmitGame" OnRender="HandleRenderCreationForm" />
|
||||||
|
</Popup>
|
||||||
|
|
||||||
|
<Popup @ref=DeletePopup Closable=false>
|
||||||
|
<ConfirmDelete OnCancel="HandleCancelPopupClicked" OnConfirm="HandleRemoveGame" />
|
||||||
</Popup>
|
</Popup>
|
||||||
@@ -1,24 +1,23 @@
|
|||||||
|
using GameIdeas.BlazorApp.Pages.Games.Components;
|
||||||
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
using GameIdeas.BlazorApp.Pages.Games.Filter;
|
||||||
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
using GameIdeas.BlazorApp.Shared.Components;
|
||||||
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
using GameIdeas.BlazorApp.Shared.Components.Popup;
|
||||||
using GameIdeas.BlazorApp.Shared.Models;
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
using GameIdeas.Shared.Dto;
|
using GameIdeas.Shared.Dto;
|
||||||
using GameIdeas.Shared.Enum;
|
using GameIdeas.Shared.Enum;
|
||||||
using Microsoft.AspNetCore.Components;
|
|
||||||
|
|
||||||
namespace GameIdeas.BlazorApp.Pages.Games;
|
namespace GameIdeas.BlazorApp.Pages.Games;
|
||||||
|
|
||||||
public partial class Games
|
public partial class Games : GameBaseComponent
|
||||||
{
|
{
|
||||||
[Inject] private IGameGateway GameGateway { get; set; } = default!;
|
|
||||||
|
|
||||||
private DisplayType DisplayType = DisplayType.List;
|
private DisplayType DisplayType = DisplayType.List;
|
||||||
private GameFilterParams GameFilter = new();
|
private GameFilterParams GameFilter = new();
|
||||||
private Popup? ManualAddPopup;
|
|
||||||
private bool IsLoading = false;
|
|
||||||
private CategoriesDto? Categories;
|
|
||||||
private IEnumerable<GameDto> GamesDto = [];
|
private IEnumerable<GameDto> GamesDto = [];
|
||||||
private int CurrentPage;
|
private int CurrentPage;
|
||||||
|
private Popup? DeletePopup;
|
||||||
|
private GameDto? GameToDelete;
|
||||||
|
private int? GameIdToUpdate;
|
||||||
|
private GameCreationForm? CreationForm;
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
@@ -33,32 +32,12 @@ public partial class Games
|
|||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleAddClicked(AddType addType)
|
private async Task HandleFetchDatas(bool displayLoader = true)
|
||||||
{
|
|
||||||
switch (addType)
|
|
||||||
{
|
|
||||||
case AddType.Manual:
|
|
||||||
ManualAddPopup?.Open();
|
|
||||||
break;
|
|
||||||
case AddType.Auto:
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void HandleBackdropManualAddClicked()
|
|
||||||
{
|
|
||||||
ManualAddPopup?.Close();
|
|
||||||
}
|
|
||||||
private async Task HandleFetchDatas(bool loadCategories = true, bool displayLoader = true)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IsLoading = displayLoader;
|
IsLoading = displayLoader;
|
||||||
|
|
||||||
if (loadCategories)
|
|
||||||
Categories = await GameGateway.FetchCategories();
|
|
||||||
|
|
||||||
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
|
GamesDto = await GameGateway.FetchGames(GameFilter, CurrentPage);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
@@ -73,6 +52,68 @@ public partial class Games
|
|||||||
private async Task HandleFilterChanged(GameFilterParams args)
|
private async Task HandleFilterChanged(GameFilterParams args)
|
||||||
{
|
{
|
||||||
GameFilter = args;
|
GameFilter = args;
|
||||||
await HandleFetchDatas(loadCategories: false, displayLoader: false);
|
await HandleFetchDatas(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleDeleteGame(GameDto args)
|
||||||
|
{
|
||||||
|
DeletePopup?.Open();
|
||||||
|
GameToDelete = args;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleCancelPopupClicked()
|
||||||
|
{
|
||||||
|
DeletePopup?.Close();
|
||||||
|
GameToDelete = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void HandleEditGame(GameDto args)
|
||||||
|
{
|
||||||
|
if (args.Id == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameIdToUpdate = args.Id;
|
||||||
|
|
||||||
|
ManualAddPopup?.Open();
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task HandleRemoveGame()
|
||||||
|
{
|
||||||
|
DeletePopup?.Close();
|
||||||
|
|
||||||
|
if (GameToDelete?.Id == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
await GameGateway.DeleteGame(GameToDelete?.Id ?? 0);
|
||||||
|
await HandleFetchDatas(false);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameToDelete = null;
|
||||||
|
}
|
||||||
|
private async Task HandleRenderCreationForm()
|
||||||
|
{
|
||||||
|
if (GameIdToUpdate != null && CreationForm != null)
|
||||||
|
{
|
||||||
|
await CreationForm.SetGameToUpdateAsync(GameIdToUpdate ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameIdToUpdate = null;
|
||||||
|
}
|
||||||
|
private async Task HandleOnSubmitGame()
|
||||||
|
{
|
||||||
|
await HandleFetchDatas(false);
|
||||||
|
await HandleFetchCategories();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -76,4 +76,28 @@ public class GameGateway(IHttpClientService httpClientService) : IGameGateway
|
|||||||
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
|
throw new CategoryNotFoundException(ResourcesKey.ErrorFetchGames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> DeleteGame(int gameIdToDelete)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await httpClientService.DeleteAsync<bool>(Endpoints.Game.Delete(gameIdToDelete));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new GameDeletionException(ResourcesKey.ErrorDeleteGame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<int> UpdateGame(GameDetailDto gameDto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await httpClientService.PutAsync<int>(Endpoints.Game.Update, gameDto);
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new GameUpdateException(ResourcesKey.ErrorUpdateGame);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,4 +9,6 @@ public interface IGameGateway
|
|||||||
Task<int> CreateGame(GameDetailDto game);
|
Task<int> CreateGame(GameDetailDto game);
|
||||||
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
|
Task<IEnumerable<GameDto>> FetchGames(GameFilterParams filter, int currentPage);
|
||||||
Task<GameDetailDto> GetGameById(int gameId);
|
Task<GameDetailDto> GetGameById(int gameId);
|
||||||
|
Task<bool> DeleteGame(int gameIdToDelete);
|
||||||
|
Task<int> UpdateGame(GameDetailDto gameDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,3 +89,16 @@
|
|||||||
.submit ::deep svg {
|
.submit ::deep svg {
|
||||||
fill: var(--green);
|
fill: var(--green);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media screen and (max-width: 700px) {
|
||||||
|
.row {
|
||||||
|
height: 104px;
|
||||||
|
display: grid;
|
||||||
|
grid-template-rows: 48px 48px;
|
||||||
|
grid-template-columns: 48px 1fr 100px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role {
|
||||||
|
grid-column: 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
using GameIdeas.BlazorApp.Pages.Games.Gateways;
|
||||||
|
using GameIdeas.BlazorApp.Shared.Models;
|
||||||
|
using GameIdeas.Shared.Dto;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
|
namespace GameIdeas.BlazorApp.Shared.Components;
|
||||||
|
|
||||||
|
public class GameBaseComponent : ComponentBase
|
||||||
|
{
|
||||||
|
[Inject] protected IGameGateway GameGateway { get; set; } = default!;
|
||||||
|
|
||||||
|
protected Popup.Popup? ManualAddPopup;
|
||||||
|
protected CategoriesDto? Categories;
|
||||||
|
protected bool IsLoading = false;
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync()
|
||||||
|
{
|
||||||
|
await HandleFetchCategories();
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task HandleFetchCategories()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IsLoading = true;
|
||||||
|
|
||||||
|
Categories = await GameGateway.FetchCategories();
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IsLoading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void HandleAddClicked(AddType addType)
|
||||||
|
{
|
||||||
|
switch (addType)
|
||||||
|
{
|
||||||
|
case AddType.Manual:
|
||||||
|
ManualAddPopup?.Open();
|
||||||
|
break;
|
||||||
|
case AddType.Auto:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void HandleBackdropManualAddClicked()
|
||||||
|
{
|
||||||
|
ManualAddPopup?.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,3 +52,20 @@
|
|||||||
.single .selected {
|
.single .selected {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***** Navigation Theme *****/
|
||||||
|
.row-option {
|
||||||
|
padding: 4px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-option:hover {
|
||||||
|
background: var(--violet-selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-option .selected {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-option:last-child {
|
||||||
|
color: var(--red);
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ public static class SelectHelper
|
|||||||
SelectTheme.AdvancedFilter => "advanced-filter",
|
SelectTheme.AdvancedFilter => "advanced-filter",
|
||||||
SelectTheme.Creation => "creation",
|
SelectTheme.Creation => "creation",
|
||||||
SelectTheme.Single => "single",
|
SelectTheme.Single => "single",
|
||||||
|
SelectTheme.RowOption => "row-option",
|
||||||
_ => string.Empty
|
_ => string.Empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,5 +7,6 @@ public enum SelectTheme
|
|||||||
Filter,
|
Filter,
|
||||||
AdvancedFilter,
|
AdvancedFilter,
|
||||||
Creation,
|
Creation,
|
||||||
Single
|
Single,
|
||||||
|
RowOption
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
@typeparam THeader
|
@typeparam THeader
|
||||||
|
|
||||||
<div class="select-container">
|
<div class="select-container">
|
||||||
<div class="button" @onclick=HandleButtonClicked>
|
<div class="button @(IsContentOpen ? "selected" : "")" @onclick=HandleButtonClicked>
|
||||||
@ChildContent
|
@ChildContent
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
|
|
||||||
@if (Params.Headers != null)
|
@if (Params.Headers != null)
|
||||||
{
|
{
|
||||||
@foreach (var header in Params.Headers.Union(HeaderValues ?? []))
|
@foreach (var header in (HeaderValues ?? []).UnionBy(Params.Headers, Params.GetHeaderLabel))
|
||||||
{
|
{
|
||||||
<SelectRow IsSelected=HeaderValues?.Contains(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.Union(Values ?? []))
|
@foreach (var item in (Values ?? []).UnionBy(Params.Items, Params.GetItemLabel))
|
||||||
{
|
{
|
||||||
<SelectRow IsSelected=Values?.Contains(item)
|
<SelectRow IsSelected=@(Values?.Contains(item))
|
||||||
Label="@Params.GetItemLabel(item)" Theme=Theme
|
Label="@Params.GetItemLabel(item)" Theme=Theme
|
||||||
OnClick="_ => HandleValueClicked(item)" />
|
OnClick="_ => HandleValueClicked(item)" />
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,13 @@ public partial class Select<TItem, THeader>
|
|||||||
if (Params.AddItem != null)
|
if (Params.AddItem != null)
|
||||||
{
|
{
|
||||||
Values ??= [];
|
Values ??= [];
|
||||||
Values.Add(Params.AddItem(AddLabel));
|
|
||||||
|
|
||||||
|
if (Type != SelectType.Multiple)
|
||||||
|
{
|
||||||
|
Values = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Values.Add(Params.AddItem(AddLabel));
|
||||||
AddLabel = string.Empty;
|
AddLabel = string.Empty;
|
||||||
|
|
||||||
await ValuesChanged.InvokeAsync(Values);
|
await ValuesChanged.InvokeAsync(Values);
|
||||||
|
|||||||
@@ -104,3 +104,13 @@
|
|||||||
.single {
|
.single {
|
||||||
border: none;
|
border: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***** Row Option Theme *****/
|
||||||
|
.dropdown.row-option {
|
||||||
|
width: auto;
|
||||||
|
right: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.row-option .content {
|
||||||
|
background: var(--violet);
|
||||||
|
}
|
||||||
|
|||||||
@@ -32,6 +32,15 @@ public partial class SelectSearch<TItem>
|
|||||||
|
|
||||||
base.OnParametersSet();
|
base.OnParametersSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnAfterRender(bool firstRender)
|
||||||
|
{
|
||||||
|
if (Values != null)
|
||||||
|
{
|
||||||
|
SearchInput?.SetText(string.Join(", ", Values.Select(GetLabel)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async Task HandleValuesChanged(IEnumerable<TItem> values)
|
private async Task HandleValuesChanged(IEnumerable<TItem> values)
|
||||||
{
|
{
|
||||||
Values = [.. values];
|
Values = [.. values];
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public static class Endpoints
|
|||||||
public const string Create = "api/Game/Create";
|
public const string Create = "api/Game/Create";
|
||||||
public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}";
|
public static string Fetch(GameFilterDto filter) => $"api/Game?{UrlHelper.BuildUrlParams(filter)}";
|
||||||
public static string FetchById(int gameId) => $"api/Game/{gameId}";
|
public static string FetchById(int gameId) => $"api/Game/{gameId}";
|
||||||
|
public static string Delete(int gameId) => $"api/Game/Delete/{gameId}";
|
||||||
|
public const string Update = "api/Game/Update";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Category
|
public static class Category
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class FetchGameDetailException(string message) : Exception(message);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class GameDeletionException(string message) : Exception(message);
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace GameIdeas.BlazorApp.Shared.Exceptions;
|
||||||
|
|
||||||
|
public class GameUpdateException(string message) : Exception(message);
|
||||||
@@ -147,9 +147,10 @@ code {
|
|||||||
.body-lg {
|
.body-lg {
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.header-1, .header-2, span, a {
|
.header-1, .header-2 {
|
||||||
display: block;
|
display: block;
|
||||||
color: var(--white);
|
color: var(--white);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
namespace GameIdeas.Resources;
|
namespace GameIdeas.Resources;
|
||||||
|
|
||||||
public class Translations(TranslationService translationService)
|
public class Translations (TranslationService translationService)
|
||||||
{
|
{
|
||||||
public string GamesIdeas => translationService.Translate(nameof(GamesIdeas));
|
public string GamesIdeas => translationService.Translate(nameof(GamesIdeas));
|
||||||
public string ManualAdd => translationService.Translate(nameof(ManualAdd));
|
public string ManualAdd => translationService.Translate(nameof(ManualAdd));
|
||||||
@@ -39,10 +39,13 @@ public class Translations(TranslationService translationService)
|
|||||||
public string ErrorFetchCategories => translationService.Translate(nameof(ErrorFetchCategories));
|
public string ErrorFetchCategories => translationService.Translate(nameof(ErrorFetchCategories));
|
||||||
public string PlaceholderAdd => translationService.Translate(nameof(PlaceholderAdd));
|
public string PlaceholderAdd => translationService.Translate(nameof(PlaceholderAdd));
|
||||||
public string ErrorCreateGame => translationService.Translate(nameof(ErrorCreateGame));
|
public string ErrorCreateGame => translationService.Translate(nameof(ErrorCreateGame));
|
||||||
|
public string ErrorDeleteGame => translationService.Translate(nameof(ErrorDeleteGame));
|
||||||
|
public string ErrorUpdateGame => translationService.Translate(nameof(ErrorUpdateGame));
|
||||||
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
|
public string InvalidTitle => translationService.Translate(nameof(InvalidTitle));
|
||||||
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
public string InvalidInterest => translationService.Translate(nameof(InvalidInterest));
|
||||||
public string Unknown => translationService.Translate(nameof(Unknown));
|
public string Unknown => translationService.Translate(nameof(Unknown));
|
||||||
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
public string ErrorFetchGames => translationService.Translate(nameof(ErrorFetchGames));
|
||||||
|
public string ErrorFetchDetail => translationService.Translate(nameof(ErrorFetchDetail));
|
||||||
public string Ascending => translationService.Translate(nameof(Ascending));
|
public string Ascending => translationService.Translate(nameof(Ascending));
|
||||||
public string Descending => translationService.Translate(nameof(Descending));
|
public string Descending => translationService.Translate(nameof(Descending));
|
||||||
public string ErrorStorageSpaceLabel => translationService.Translate(nameof(ErrorStorageSpaceLabel));
|
public string ErrorStorageSpaceLabel => translationService.Translate(nameof(ErrorStorageSpaceLabel));
|
||||||
@@ -68,6 +71,9 @@ public class Translations(TranslationService translationService)
|
|||||||
public string About => translationService.Translate(nameof(About));
|
public string About => translationService.Translate(nameof(About));
|
||||||
public string ReadMore => translationService.Translate(nameof(ReadMore));
|
public string ReadMore => translationService.Translate(nameof(ReadMore));
|
||||||
public string ReadLess => translationService.Translate(nameof(ReadLess));
|
public string ReadLess => translationService.Translate(nameof(ReadLess));
|
||||||
|
public string Detail => translationService.Translate(nameof(Detail));
|
||||||
|
public string Edit => translationService.Translate(nameof(Edit));
|
||||||
|
public string Delete => translationService.Translate(nameof(Delete));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ResourcesKey
|
public static class ResourcesKey
|
||||||
@@ -115,10 +121,13 @@ public static class ResourcesKey
|
|||||||
public static string ErrorFetchCategories => _instance?.ErrorFetchCategories ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchCategories is not initialized.");
|
public static string ErrorFetchCategories => _instance?.ErrorFetchCategories ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchCategories is not initialized.");
|
||||||
public static string PlaceholderAdd => _instance?.PlaceholderAdd ?? throw new InvalidOperationException("ResourcesKey.PlaceholderAdd is not initialized.");
|
public static string PlaceholderAdd => _instance?.PlaceholderAdd ?? throw new InvalidOperationException("ResourcesKey.PlaceholderAdd is not initialized.");
|
||||||
public static string ErrorCreateGame => _instance?.ErrorCreateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateGame is not initialized.");
|
public static string ErrorCreateGame => _instance?.ErrorCreateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorCreateGame is not initialized.");
|
||||||
|
public static string ErrorDeleteGame => _instance?.ErrorDeleteGame ?? throw new InvalidOperationException("ResourcesKey.ErrorDeleteGame is not initialized.");
|
||||||
|
public static string ErrorUpdateGame => _instance?.ErrorUpdateGame ?? throw new InvalidOperationException("ResourcesKey.ErrorUpdateGame is not initialized.");
|
||||||
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized.");
|
public static string InvalidTitle => _instance?.InvalidTitle ?? throw new InvalidOperationException("ResourcesKey.InvalidTitle is not initialized.");
|
||||||
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
public static string InvalidInterest => _instance?.InvalidInterest ?? throw new InvalidOperationException("ResourcesKey.InvalidInterest is not initialized.");
|
||||||
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
public static string Unknown => _instance?.Unknown ?? throw new InvalidOperationException("ResourcesKey.Unknown is not initialized.");
|
||||||
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
public static string ErrorFetchGames => _instance?.ErrorFetchGames ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchGames is not initialized.");
|
||||||
|
public static string ErrorFetchDetail => _instance?.ErrorFetchDetail ?? throw new InvalidOperationException("ResourcesKey.ErrorFetchDetail is not initialized.");
|
||||||
public static string Ascending => _instance?.Ascending ?? throw new InvalidOperationException("ResourcesKey.Ascending is not initialized.");
|
public static string Ascending => _instance?.Ascending ?? throw new InvalidOperationException("ResourcesKey.Ascending is not initialized.");
|
||||||
public static string Descending => _instance?.Descending ?? throw new InvalidOperationException("ResourcesKey.Descending is not initialized.");
|
public static string Descending => _instance?.Descending ?? throw new InvalidOperationException("ResourcesKey.Descending is not initialized.");
|
||||||
public static string ErrorStorageSpaceLabel => _instance?.ErrorStorageSpaceLabel ?? throw new InvalidOperationException("ResourcesKey.ErrorStorageSpaceLabel is not initialized.");
|
public static string ErrorStorageSpaceLabel => _instance?.ErrorStorageSpaceLabel ?? throw new InvalidOperationException("ResourcesKey.ErrorStorageSpaceLabel is not initialized.");
|
||||||
@@ -144,4 +153,7 @@ public static class ResourcesKey
|
|||||||
public static string About => _instance?.About ?? throw new InvalidOperationException("ResourcesKey.About is not initialized.");
|
public static string About => _instance?.About ?? throw new InvalidOperationException("ResourcesKey.About is not initialized.");
|
||||||
public static string ReadMore => _instance?.ReadMore ?? throw new InvalidOperationException("ResourcesKey.ReadMore is not initialized.");
|
public static string ReadMore => _instance?.ReadMore ?? throw new InvalidOperationException("ResourcesKey.ReadMore is not initialized.");
|
||||||
public static string ReadLess => _instance?.ReadLess ?? throw new InvalidOperationException("ResourcesKey.ReadLess is not initialized.");
|
public static string ReadLess => _instance?.ReadLess ?? throw new InvalidOperationException("ResourcesKey.ReadLess is not initialized.");
|
||||||
|
public static string Detail => _instance?.Detail ?? throw new InvalidOperationException("ResourcesKey.Detail is not initialized.");
|
||||||
|
public static string Edit => _instance?.Edit ?? throw new InvalidOperationException("ResourcesKey.Edit is not initialized.");
|
||||||
|
public static string Delete => _instance?.Delete ?? throw new InvalidOperationException("ResourcesKey.Delete is not initialized.");
|
||||||
}
|
}
|
||||||
@@ -1,67 +1,73 @@
|
|||||||
{
|
{
|
||||||
"GamesIdeas": "Game Ideas",
|
"GamesIdeas": "Game Ideas",
|
||||||
"ManualAdd": "Manuel",
|
"ManualAdd": "Manuel",
|
||||||
"AutoAdd": "Automatique",
|
"AutoAdd": "Automatique",
|
||||||
"Login": "Se connecter",
|
"Login": "Se connecter",
|
||||||
"Logout": "Se déconnecter",
|
"Logout": "Se déconnecter",
|
||||||
"EnterUsername": "Nom d'utilisateur",
|
"EnterUsername": "Nom d'utilisateur",
|
||||||
"EnterPassword": "Mot de passe",
|
"EnterPassword": "Mot de passe",
|
||||||
"UserManager": "Gestion des utilisateurs",
|
"UserManager": "Gestion des utilisateurs",
|
||||||
"CategoriesManager": "Gestion des catégories",
|
"CategoriesManager": "Gestion des catégories",
|
||||||
"Filters": "Les filtres",
|
"Filters": "Les filtres",
|
||||||
"LastAdd": "Les ajouts récents",
|
"LastAdd": "Les ajouts récents",
|
||||||
"Research": "Rechercher",
|
"Research": "Rechercher",
|
||||||
"Platforms": "Plateformes",
|
"Platforms": "Plateformes",
|
||||||
"Tags": "Genres",
|
"Tags": "Genres",
|
||||||
"Publisher": "Editeur",
|
"Publisher": "Editeur",
|
||||||
"Developer": "Développeur",
|
"Developer": "Développeur",
|
||||||
"StorageSize": "Taille d'espace",
|
"StorageSize": "Taille d'espace",
|
||||||
"StorageSizeMo": "Taille d'espace en Mo",
|
"StorageSizeMo": "Taille d'espace en Mo",
|
||||||
"LastModification": "Dernière modifications",
|
"LastModification": "Dernière modifications",
|
||||||
"ReleaseDate": "Date de parution",
|
"ReleaseDate": "Date de parution",
|
||||||
"CreateDate": "Date de création",
|
"CreateDate": "Date de création",
|
||||||
"UpdateDate": "Date de modification",
|
"UpdateDate": "Date de modification",
|
||||||
"Title": "Titre",
|
"Title": "Titre",
|
||||||
"Interest": "Intérêt",
|
"Interest": "Intérêt",
|
||||||
"Properties": "Propriétés",
|
"Properties": "Propriétés",
|
||||||
"Description": "Description",
|
"Description": "Description",
|
||||||
"Save": "Enregister",
|
"Save": "Enregister",
|
||||||
"Reset": "Annuler",
|
"Reset": "Annuler",
|
||||||
"ErrorWhenPostingData": "Erreur lors de la requête POST",
|
"ErrorWhenPostingData": "Erreur lors de la requête POST",
|
||||||
"ErrorWhenPutingData": "Erreur lors de la requête PUT",
|
"ErrorWhenPutingData": "Erreur lors de la requête PUT",
|
||||||
"ErrorWhenDeletingData": "Erreur lors de la requête DELETE",
|
"ErrorWhenDeletingData": "Erreur lors de la requête DELETE",
|
||||||
"ErrorWhenFetchingData": "Erreur lors de la requête GET",
|
"ErrorWhenFetchingData": "Erreur lors de la requête GET",
|
||||||
"RequestFailedStatusFormat": "Erreur lors de la réponse, code {0}",
|
"RequestFailedStatusFormat": "Erreur lors de la réponse, code {0}",
|
||||||
"ErrorFetchCategories": "Erreur lors de la récupération des catégories",
|
"ErrorFetchCategories": "Erreur lors de la récupération des catégories",
|
||||||
"PlaceholderAdd": "Ajouter un nouveau",
|
"PlaceholderAdd": "Ajouter un nouveau",
|
||||||
"ErrorCreateGame": "Erreur lors de la création d'un jeu",
|
"ErrorCreateGame": "Erreur lors de la création d'un jeu",
|
||||||
"InvalidTitle": "Le titre est incorrect",
|
"ErrorDeleteGame": "Erreur lors de la suppression d'un jeu",
|
||||||
"InvalidInterest": "L'interêt est incorrect",
|
"ErrorUpdateGame": "Erreur lors de la modification d'un jeu",
|
||||||
"Unknown": "Inconnu",
|
"InvalidTitle": "Le titre est incorrect",
|
||||||
"ErrorFetchGames": "Erreur lors de la récupération des jeux",
|
"InvalidInterest": "L'interêt est incorrect",
|
||||||
"Ascending": "Ascendant",
|
"Unknown": "Inconnu",
|
||||||
"Descending": "Descendant",
|
"ErrorFetchGames": "Erreur lors de la récupération des jeux",
|
||||||
"ErrorStorageSpaceLabel": "Erreur lors de la génération des label de l'espace de stockage",
|
"ErrorFetchDetail": "Erreur lors de la récupération des détails d'un jeu",
|
||||||
"MinStorageSpaceFormat": "Jusqu'à {0}",
|
"Ascending": "Ascendant",
|
||||||
"MaxStorageSpaceFormat": "Plus de {0}",
|
"Descending": "Descendant",
|
||||||
"MinMaxStorageSpaceFormat": "{0} à {1}",
|
"ErrorStorageSpaceLabel": "Erreur lors de la génération des label de l'espace de stockage",
|
||||||
"UserArgumentsNull": "Nom d'utilisateur ou mot de passe invalide",
|
"MinStorageSpaceFormat": "Jusqu'à {0}",
|
||||||
"InvalidToken": "Le token JWT est invalide",
|
"MaxStorageSpaceFormat": "Plus de {0}",
|
||||||
"UserUnauthorized": "Utilisateur non authorisé",
|
"MinMaxStorageSpaceFormat": "{0} à {1}",
|
||||||
"UserLoginFailed": "Authentification de l'utilisateur échoué",
|
"UserArgumentsNull": "Nom d'utilisateur ou mot de passe invalide",
|
||||||
"UserLogoutFailed": "Déconnection de l'utilisateur échoué",
|
"InvalidToken": "Le token JWT est invalide",
|
||||||
"Roles": "Rôles",
|
"UserUnauthorized": "Utilisateur non authorisé",
|
||||||
"ErrorFetchUsers": "Erreur lors de la récupération des utilisateurs",
|
"UserLoginFailed": "Authentification de l'utilisateur échoué",
|
||||||
"ErrorFetchRoles": "Erreur lors de la récupération des rôles",
|
"UserLogoutFailed": "Déconnection de l'utilisateur échoué",
|
||||||
"MissingField": "Un champs est manquant",
|
"Roles": "Rôles",
|
||||||
"ErrorCreateUser": "Erreur lors de la création d'un utilisateur",
|
"ErrorFetchUsers": "Erreur lors de la récupération des utilisateurs",
|
||||||
"ErrorUpdateUser": "Erreur lors de la mise à jour d'un utilisateur",
|
"ErrorFetchRoles": "Erreur lors de la récupération des rôles",
|
||||||
"ErrorDeleteUser": "Erreur lors de la suppression d'un utilisateur",
|
"MissingField": "Un champs est manquant",
|
||||||
"Cancel": "Annuler",
|
"ErrorCreateUser": "Erreur lors de la création d'un utilisateur",
|
||||||
"Confirm": "Confirmer",
|
"ErrorUpdateUser": "Erreur lors de la mise à jour d'un utilisateur",
|
||||||
"ConfirmDeleteDescription": "Êtes-vous sur de vouloir supprimer cet élément ?",
|
"ErrorDeleteUser": "Erreur lors de la suppression d'un utilisateur",
|
||||||
"Informations": "Informations",
|
"Cancel": "Annuler",
|
||||||
"About": "À propos",
|
"Confirm": "Confirmer",
|
||||||
"ReadMore": "Afficher",
|
"ConfirmDeleteDescription": "Êtes-vous sur de vouloir supprimer cet élément ?",
|
||||||
"ReadLess": "Réduire"
|
"Informations": "Informations",
|
||||||
|
"About": "À propos",
|
||||||
|
"ReadMore": "Afficher",
|
||||||
|
"ReadLess": "Réduire",
|
||||||
|
"Detail": "Détail",
|
||||||
|
"Edit": "Modifier",
|
||||||
|
"Delete": "Supprimer"
|
||||||
}
|
}
|
||||||
@@ -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