2023-02-16 17:38:01 +01:00
|
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
2023-02-17 18:29:20 +01:00
|
|
|
|
using MudBlazor;
|
|
|
|
|
using Shared.Dto.Api;
|
|
|
|
|
using Shared.Models;
|
2023-02-16 17:38:01 +01:00
|
|
|
|
|
|
|
|
|
namespace WebUI.Pages;
|
|
|
|
|
|
|
|
|
|
public partial class Cards
|
|
|
|
|
{
|
|
|
|
|
[Inject]
|
2023-02-17 18:29:20 +01:00
|
|
|
|
public required HttpClient Client { get; set; }
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public required IDialogService DialogService { get; set; }
|
2023-02-16 17:38:01 +01:00
|
|
|
|
|
|
|
|
|
private List<ClientCardDto>? CardDtos { get; set; }
|
|
|
|
|
|
|
|
|
|
private string ErrorMessage { get; set; } = string.Empty;
|
|
|
|
|
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
await base.OnInitializedAsync();
|
|
|
|
|
var result = await Client.GetFromJsonAsync<ServiceResult<List<ClientCardDto>>>("api/Profiles");
|
|
|
|
|
if (result is null)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = "Parse result failed";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!result.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
ErrorMessage = result.Error!.Message;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
CardDtos = result.Data;
|
|
|
|
|
}
|
2023-02-17 18:29:20 +01:00
|
|
|
|
|
|
|
|
|
private async Task OnEditPlayerNameClicked(ClientCardDto card)
|
|
|
|
|
{
|
|
|
|
|
var options = new DialogOptions
|
|
|
|
|
{
|
|
|
|
|
CloseOnEscapeKey = false,
|
|
|
|
|
DisableBackdropClick = true,
|
|
|
|
|
FullWidth = true
|
|
|
|
|
};
|
|
|
|
|
var parameters = new DialogParameters { { "Data", card } };
|
|
|
|
|
var dialog = await DialogService.ShowAsync<ChangePlayerNameDialog>("Favorite", parameters, options);
|
|
|
|
|
var result = await dialog.Result;
|
|
|
|
|
}
|
2023-02-16 17:38:01 +01:00
|
|
|
|
}
|