2024-06-05 03:07:33 +02:00
|
|
|
|
using Blazored.LocalStorage;
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
|
|
|
|
namespace TaikoWebUI.Pages.Dialogs;
|
2023-11-12 18:56:57 +01:00
|
|
|
|
|
|
|
|
|
public partial class AccessCodeDeleteConfirmDialog
|
|
|
|
|
{
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2024-05-17 00:32:46 +02:00
|
|
|
|
[CascadingParameter] private MudDialogInstance MudDialog { get; set; } = null!;
|
2023-11-12 18:56:57 +01:00
|
|
|
|
|
|
|
|
|
[Parameter]
|
|
|
|
|
public User User { get; set; } = new();
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
[Parameter]
|
|
|
|
|
public string AccessCode { get; set; } = "";
|
2024-05-17 00:32:46 +02:00
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public ILocalStorageService LocalStorage { get; set; } = null!;
|
|
|
|
|
|
|
|
|
|
[Inject]
|
|
|
|
|
public AuthService AuthService { get; set; } = null!;
|
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
|
|
|
|
|
private void Cancel() => MudDialog.Cancel();
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
private async Task DeleteAccessCode()
|
|
|
|
|
{
|
|
|
|
|
if (User.AccessCodes.Count == 1)
|
|
|
|
|
{
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Snackbar.Add(Localizer["Access Code Delete Last Access Code Error"], Severity.Error);
|
2023-11-12 18:56:57 +01:00
|
|
|
|
MudDialog.Close(DialogResult.Ok(false));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-09 00:42:56 +01:00
|
|
|
|
|
2023-11-12 18:56:57 +01:00
|
|
|
|
var cardResponseMessage = await Client.DeleteAsync($"api/Cards/{AccessCode}");
|
|
|
|
|
|
|
|
|
|
if (!cardResponseMessage.IsSuccessStatusCode)
|
|
|
|
|
{
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Snackbar.Add(Localizer["Unknown Error"], Severity.Error);
|
2023-11-12 18:56:57 +01:00
|
|
|
|
MudDialog.Close(DialogResult.Ok(false));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-05 03:07:33 +02:00
|
|
|
|
Snackbar.Add(Localizer["Access Code Delete Success"], Severity.Success);
|
2023-11-12 18:56:57 +01:00
|
|
|
|
MudDialog.Close(DialogResult.Ok(true));
|
|
|
|
|
}
|
|
|
|
|
}
|