示例#1
0
    private async Task ImportChallengeAsync(ChallengeAdminViewDto challenge)
    {
        _ = challenge ?? throw new ArgumentNullException(nameof(challenge));

        PopupService.DisplayLoader("Restoration");

        try
        {
            Error = null;
            if (challenge.GameId == -1)
            {
                await ChallengesApi.ImportChallengeAsync(new() { GeoGuessrId = challenge.GeoGuessrId, OverrideData = true });
            }
            else
            {
                await GamesApi.UpdateChallengesAsync(challenge.GameId);
            }
        }
        catch (ApiException e)
        {
            Error = $"Error: {e.Content}";
        }
        finally
        {
            await OnInitializedAsync();

            ChallengesTable.SetItems(Challenges);
            PopupService.HidePopup();
            StateHasChanged();
        }
    }
    private async Task RefreshAsync()
    {
        try
        {
            PopupService.DisplayLoader("Restoration");
            await ChallengesApi.ImportChallengeAsync(new() { GeoGuessrId = Challenge.GeoGuessrId, OverrideData = true });

            ApiResponse <ChallengeDetailDto> response = await ChallengesApi.GetAsync(Challenge.Id);

            Challenge = response.Content !;
        }
        catch (ApiException e)
        {
            ToastService.DisplayToast(e.Content ?? "Echec de l'opération", null, ToastType.Error, "challenge-refresh", true);
        }
        finally
        {
            PopupService.HidePopup();
            StateHasChanged();
        }
    }