1
0
mirror of synced 2024-12-05 03:17:58 +01:00
TaikoLocalServer/TaikoWebUI/Pages/Dialogs/AccessCodeDeleteConfirmDialog.razor.cs

38 lines
1.0 KiB
C#
Raw Normal View History

namespace TaikoWebUI.Pages.Dialogs;
public partial class AccessCodeDeleteConfirmDialog
{
2024-03-09 00:42:56 +01:00
[CascadingParameter]
MudDialogInstance MudDialog { get; set; } = null!;
[Parameter]
public User User { get; set; } = new();
2024-03-09 00:42:56 +01:00
[Parameter]
public string AccessCode { get; set; } = "";
private void Cancel() => MudDialog.Cancel();
2024-03-09 00:42:56 +01:00
private async Task DeleteAccessCode()
{
if (User.AccessCodes.Count == 1)
{
Snackbar.Add("Cannot delete last access code!", Severity.Error);
MudDialog.Close(DialogResult.Ok(false));
return;
}
2024-03-09 00:42:56 +01:00
var cardResponseMessage = await Client.DeleteAsync($"api/Cards/{AccessCode}");
if (!cardResponseMessage.IsSuccessStatusCode)
{
Snackbar.Add("Something went wrong when deleting access code!", Severity.Error);
MudDialog.Close(DialogResult.Ok(false));
return;
}
Snackbar.Add("Delete success!", Severity.Success);
MudDialog.Close(DialogResult.Ok(true));
}
}