Add delete api
Add delete dialog
This commit is contained in:
parent
6814715ddb
commit
1097c3cd24
@ -1,4 +1,5 @@
|
||||
namespace SharedProject.Enums;
|
||||
// ReSharper disable UnusedMember.Global
|
||||
namespace SharedProject.Enums;
|
||||
|
||||
public enum RandomType
|
||||
{
|
||||
|
30
TaikoLocalServer/Controllers/Api/CardsController.cs
Normal file
30
TaikoLocalServer/Controllers/Api/CardsController.cs
Normal file
@ -0,0 +1,30 @@
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class CardsController : BaseController<CardsController>
|
||||
{
|
||||
private readonly TaikoDbContext context;
|
||||
|
||||
public CardsController(TaikoDbContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
[HttpDelete("{accessCode}")]
|
||||
public async Task<IActionResult> DeleteUser(string accessCode)
|
||||
{
|
||||
var card = await context.Cards.FindAsync(accessCode);
|
||||
|
||||
if (card is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
context.Cards.Remove(card);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
}
|
@ -45,7 +45,7 @@ public class UserSettingsController : BaseController<UserSettingsController>
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
|
||||
{
|
||||
var user = await context.UserData.FirstOrDefaultAsync(datum => datum.Baid == baid);
|
||||
var user = await context.UserData.FindAsync(baid);
|
||||
|
||||
if (user is null)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@
|
||||
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
<PackageReference Include="Throw" Version="1.3.0" />
|
||||
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="0.2.1" />
|
||||
</ItemGroup>
|
||||
|
@ -4,7 +4,7 @@
|
||||
@using SharedProject.Models
|
||||
@inject HttpClient Client
|
||||
|
||||
<MudBreadcrumbs Items="_breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
||||
<MudBreadcrumbs Items="breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
||||
|
||||
<h1>Card: @Baid</h1>
|
||||
|
||||
@ -21,21 +21,21 @@
|
||||
<MudTextField @bind-Value="@response.Title" Label="Title" Variant="Variant.Outlined"></MudTextField>
|
||||
|
||||
<MudSelect @bind-Value="@response.IsDisplayAchievement"
|
||||
Label="Display Achievement Panel">
|
||||
Label="Display Achievement Panel">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
|
||||
<MudSelect @bind-Value="@response.IsDisplayDanOnNamePlate"
|
||||
Label="Display Dan Rank on Name Plate">
|
||||
Label="Display Dan Rank on Name Plate">
|
||||
<MudSelectItem Value="@true">On</MudSelectItem>
|
||||
<MudSelectItem Value="@false">Off</MudSelectItem>
|
||||
</MudSelect>
|
||||
<MudSelect @bind-Value="@response.AchievementDisplayDifficulty"
|
||||
Label="Achievement Panel Difficulty">
|
||||
Label="Achievement Panel Difficulty">
|
||||
@foreach (var item in Enum.GetValues<Difficulty>())
|
||||
{
|
||||
<MudSelectItem Value="@item" />
|
||||
<MudSelectItem Value="@item"/>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudStack>
|
||||
@ -47,13 +47,13 @@
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="4">
|
||||
<MudStack Spacing="6">
|
||||
<MudSwitch @bind-Checked="@response.PlaySetting.IsVanishOn" Label="Vanish" Color="Color.Primary" />
|
||||
<MudSwitch @bind-Checked="@response.PlaySetting.IsVanishOn" Label="Vanish" Color="Color.Primary"/>
|
||||
|
||||
<MudSwitch @bind-Checked="@response.PlaySetting.IsInverseOn" Label="Inverse" Color="Color.Primary" />
|
||||
<MudSwitch @bind-Checked="@response.PlaySetting.IsInverseOn" Label="Inverse" Color="Color.Primary"/>
|
||||
|
||||
<MudSwitch @bind-Checked="@response.IsSkipOn" Label="Give Up" Color="Color.Primary" />
|
||||
<MudSwitch @bind-Checked="@response.IsSkipOn" Label="Give Up" Color="Color.Primary"/>
|
||||
|
||||
<MudSwitch @bind-Checked="@response.IsVoiceOn" Label="Voice" Color="Color.Primary" />
|
||||
<MudSwitch @bind-Checked="@response.IsVoiceOn" Label="Voice" Color="Color.Primary"/>
|
||||
</MudStack>
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="8">
|
||||
@ -67,10 +67,10 @@
|
||||
</MudSelect>
|
||||
|
||||
<MudSelect @bind-Value="@response.PlaySetting.RandomType"
|
||||
Label="Random">
|
||||
Label="Random">
|
||||
@foreach (var item in Enum.GetValues<RandomType>())
|
||||
{
|
||||
<MudSelectItem Value="@item" />
|
||||
<MudSelectItem Value="@item"/>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
@ -86,12 +86,12 @@
|
||||
<MudItem md="4" xs="12" Class="py-8 px-8 my-4 pt-8">
|
||||
<MudStack Spacing="6" Style="top:100px" Class="sticky">
|
||||
<MudButton Disabled="@isSavingOptions"
|
||||
OnClick="SaveOptions"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary">
|
||||
OnClick="SaveOptions"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary">
|
||||
@if (isSavingOptions)
|
||||
{
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true" />
|
||||
<MudProgressCircular Class="ms-n1" Size="Size.Small" Indeterminate="true"/>
|
||||
<MudText Class="ms-2">Saving...</MudText>
|
||||
}
|
||||
else
|
||||
@ -105,9 +105,8 @@
|
||||
</MudGrid>
|
||||
|
||||
<MudScrollToTop>
|
||||
<MudFab Color="Color.Secondary" Icon="@Icons.Filled.ArrowCircleUp" />
|
||||
<MudFab Color="Color.Secondary" Icon="@Icons.Filled.ArrowCircleUp"/>
|
||||
</MudScrollToTop>
|
||||
|
||||
}
|
||||
|
||||
@code {
|
||||
@ -119,12 +118,16 @@
|
||||
|
||||
private bool isSavingOptions;
|
||||
|
||||
private readonly string[] speedStrings = { "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9",
|
||||
"2.0", "2.5", "3.0", "3.5", "4.0"};
|
||||
private readonly string[] speedStrings =
|
||||
{
|
||||
"1.0", "1.1", "1.2", "1.3", "1.4",
|
||||
"1.5", "1.6", "1.7", "1.8", "1.9",
|
||||
"2.0", "2.5", "3.0", "3.5", "4.0"
|
||||
};
|
||||
|
||||
private readonly string[] notePositionStrings = new string[] { "-5", "-4", "-3", "-2", "-1", "0", "+1", "+2", "+3", "+4", "+5"};
|
||||
private readonly string[] notePositionStrings = { "-5", "-4", "-3", "-2", "-1", "0", "+1", "+2", "+3", "+4", "+5" };
|
||||
|
||||
private List<BreadcrumbItem> _breadcrumbs = new List<BreadcrumbItem>
|
||||
private List<BreadcrumbItem> breadcrumbs = new()
|
||||
{
|
||||
new BreadcrumbItem("Dashboard", href: "Dashboard"),
|
||||
};
|
||||
@ -135,7 +138,7 @@
|
||||
isSavingOptions = false;
|
||||
response = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
||||
|
||||
_breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
|
||||
breadcrumbs.Add(new BreadcrumbItem($"Card: {Baid}", href: null, disabled: true));
|
||||
}
|
||||
|
||||
private async Task SaveOptions()
|
||||
@ -143,5 +146,6 @@
|
||||
isSavingOptions = true;
|
||||
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
||||
isSavingOptions = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,77 +1,87 @@
|
||||
@using SharedProject.Models.Responses
|
||||
@using TaikoWebUI.Pages.Dialogs
|
||||
@using SharedProject.Models
|
||||
@inject HttpClient Client
|
||||
@inject NavigationManager UriHelper
|
||||
@inject IDialogService DialogService
|
||||
|
||||
@page "/Dashboard"
|
||||
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
<MudGrid Class="my-8">
|
||||
@if (response is null)
|
||||
{
|
||||
@if (isLoading is true) {
|
||||
@for (uint i = 0; i < 3; i++) {
|
||||
@if (response is null)
|
||||
{
|
||||
@for (uint i = 0; i < 3; i++)
|
||||
{
|
||||
<MudItem xs="12" md="6" lg="4">
|
||||
<MudCard Outlined="true">
|
||||
<MudCardContent>
|
||||
<MudSkeleton Width="30%" Height="42px;" Class="mb-5" />
|
||||
<MudSkeleton Width="80%" />
|
||||
<MudSkeleton Width="100%" />
|
||||
<MudSkeleton Width="30%" Height="42px;" Class="mb-5"/>
|
||||
<MudSkeleton Width="80%"/>
|
||||
<MudSkeleton Width="100%"/>
|
||||
</MudCardContent>
|
||||
<MudCardActions>
|
||||
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
|
||||
<MudSkeleton Width="64px" Height="40px" />
|
||||
<MudSkeleton Width="64px" Height="40px" />
|
||||
<MudSkeleton Width="64px" Height="40px"/>
|
||||
<MudSkeleton Width="64px" Height="40px"/>
|
||||
</MudStack>
|
||||
</MudCardActions>
|
||||
</MudCard>
|
||||
</MudItem>
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else if(response.Users.Count != 0)
|
||||
{
|
||||
@foreach (var user in response.Users)
|
||||
{
|
||||
<MudItem xs="12" md="6" lg="4">
|
||||
<MudCard Outlined="true">
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h6" Style="font-weight:bold">@user.Baid</MudText>
|
||||
</CardHeaderContent>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<MudText Style="font-weight:bold">Access Code</MudText>
|
||||
<MudText Style="font-family:monospace">@user.AccessCode</MudText>
|
||||
</MudCardContent>
|
||||
<MudCardActions>
|
||||
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Delete"
|
||||
Color="Color.Error"
|
||||
OnClick="_ => DeleteCard(user)">
|
||||
Delete
|
||||
</MudButton>
|
||||
<MudButton OnClick="() => NavigateToProfile(user.Baid)"
|
||||
Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Edit"
|
||||
Color="Color.Primary">
|
||||
Edit
|
||||
</MudButton>
|
||||
</MudStack>
|
||||
</MudCardActions>
|
||||
</MudCard>
|
||||
</MudItem>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudItem xs="12">
|
||||
<MudText Align="Align.Center" Class="my-8">
|
||||
No data.
|
||||
</MudText>
|
||||
</MudItem>
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@foreach (var user in response.Users)
|
||||
{
|
||||
<MudItem xs="12" md="6" lg="4">
|
||||
<MudCard Outlined="true">
|
||||
<MudCardHeader>
|
||||
<CardHeaderContent>
|
||||
<MudText Typo="Typo.h6" Style="font-weight:bold">@user.Baid</MudText>
|
||||
</CardHeaderContent>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<MudText Style="font-weight:bold">Access Code</MudText>
|
||||
<MudText Style="font-family:monospace">@user.AccessCode</MudText>
|
||||
</MudCardContent>
|
||||
<MudCardActions>
|
||||
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Delete" Color="Color.Error">Delete</MudButton>
|
||||
<MudButton OnClick="() => NavigateToProfile(user.Baid)" Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Edit" Color="Color.Primary">Edit</MudButton>
|
||||
</MudStack>
|
||||
</MudCardActions>
|
||||
</MudCard>
|
||||
</MudItem>
|
||||
}
|
||||
}
|
||||
</MudGrid>
|
||||
|
||||
|
||||
@code {
|
||||
private DashboardResponse? response;
|
||||
private bool isLoading = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
||||
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
|
||||
@ -79,4 +89,23 @@ else
|
||||
{
|
||||
UriHelper.NavigateTo($"/Card/{baid}");
|
||||
}
|
||||
|
||||
private async Task DeleteCard(User user)
|
||||
{
|
||||
var parameters = new DialogParameters
|
||||
{
|
||||
["user"] = user
|
||||
};
|
||||
|
||||
var dialog = DialogService.Show<CardDeleteConfirmDialog>("Delete Card", parameters);
|
||||
var result = await dialog.Result;
|
||||
|
||||
if (result.Cancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
||||
}
|
||||
|
||||
}
|
51
TaikoWebUI/Pages/Dialogs/CardDeleteConfirmDialog.razor
Normal file
51
TaikoWebUI/Pages/Dialogs/CardDeleteConfirmDialog.razor
Normal file
@ -0,0 +1,51 @@
|
||||
@using SharedProject.Models
|
||||
@inject HttpClient Client
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudDialog>
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
<MudIcon Icon="@Icons.Material.Filled.DeleteForever" Class="mr-3 mb-n1"/>
|
||||
Delete card?
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudText>
|
||||
Do you really want to delete the card?
|
||||
All the related data will also be deleted and this process cannot be undone!
|
||||
</MudText>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
<MudButton Color="Color.Error" OnClick="DeleteCard">
|
||||
<MudText>Delete Card</MudText>
|
||||
</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
|
||||
[CascadingParameter]
|
||||
MudDialogInstance MudDialog { get; set; } = null!;
|
||||
|
||||
[Parameter]
|
||||
public User User { get; set; } = new();
|
||||
|
||||
private void Cancel() => MudDialog.Cancel();
|
||||
|
||||
private async Task DeleteCard()
|
||||
{
|
||||
var responseMessage = await Client.DeleteAsync($"api/Cards/{User.AccessCode}");
|
||||
|
||||
if (!responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
Snackbar.Add("Something went wrong when deleting card!", Severity.Error);
|
||||
MudDialog.Close(DialogResult.Ok(false));
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("Delete success!", Severity.Success);
|
||||
MudDialog.Close(DialogResult.Ok(true));
|
||||
}
|
||||
|
||||
}
|
@ -9,7 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.7" PrivateAssets="all" />
|
||||
<PackageReference Include="MudBlazor" Version="6.0.13" />
|
||||
<PackageReference Include="MudBlazor" Version="6.0.15" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user