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
|
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]
|
[HttpPost]
|
||||||
public async Task<IActionResult> SaveUserSetting(uint baid, UserSetting userSetting)
|
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)
|
if (user is null)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||||
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
<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="Throw" Version="1.3.0" />
|
||||||
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="0.2.1" />
|
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="0.2.1" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
@using SharedProject.Models
|
@using SharedProject.Models
|
||||||
@inject HttpClient Client
|
@inject HttpClient Client
|
||||||
|
|
||||||
<MudBreadcrumbs Items="_breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
<MudBreadcrumbs Items="breadcrumbs" Class="px-0"></MudBreadcrumbs>
|
||||||
|
|
||||||
<h1>Card: @Baid</h1>
|
<h1>Card: @Baid</h1>
|
||||||
|
|
||||||
@ -107,7 +107,6 @@
|
|||||||
<MudScrollToTop>
|
<MudScrollToTop>
|
||||||
<MudFab Color="Color.Secondary" Icon="@Icons.Filled.ArrowCircleUp"/>
|
<MudFab Color="Color.Secondary" Icon="@Icons.Filled.ArrowCircleUp"/>
|
||||||
</MudScrollToTop>
|
</MudScrollToTop>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
@ -119,12 +118,16 @@
|
|||||||
|
|
||||||
private bool isSavingOptions;
|
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",
|
private readonly string[] speedStrings =
|
||||||
"2.0", "2.5", "3.0", "3.5", "4.0"};
|
{
|
||||||
|
"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"),
|
new BreadcrumbItem("Dashboard", href: "Dashboard"),
|
||||||
};
|
};
|
||||||
@ -135,7 +138,7 @@
|
|||||||
isSavingOptions = false;
|
isSavingOptions = false;
|
||||||
response = await Client.GetFromJsonAsync<UserSetting>($"api/UserSettings/{Baid}");
|
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()
|
private async Task SaveOptions()
|
||||||
@ -144,4 +147,5 @@
|
|||||||
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
await Client.PostAsJsonAsync($"api/UserSettings/{Baid}", response);
|
||||||
isSavingOptions = false;
|
isSavingOptions = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,9 @@
|
|||||||
@using SharedProject.Models.Responses
|
@using SharedProject.Models.Responses
|
||||||
|
@using TaikoWebUI.Pages.Dialogs
|
||||||
|
@using SharedProject.Models
|
||||||
@inject HttpClient Client
|
@inject HttpClient Client
|
||||||
@inject NavigationManager UriHelper
|
@inject NavigationManager UriHelper
|
||||||
|
@inject IDialogService DialogService
|
||||||
|
|
||||||
@page "/Dashboard"
|
@page "/Dashboard"
|
||||||
|
|
||||||
@ -9,8 +12,8 @@
|
|||||||
<MudGrid Class="my-8">
|
<MudGrid Class="my-8">
|
||||||
@if (response is null)
|
@if (response is null)
|
||||||
{
|
{
|
||||||
@if (isLoading is true) {
|
@for (uint i = 0; i < 3; i++)
|
||||||
@for (uint i = 0; i < 3; i++) {
|
{
|
||||||
<MudItem xs="12" md="6" lg="4">
|
<MudItem xs="12" md="6" lg="4">
|
||||||
<MudCard Outlined="true">
|
<MudCard Outlined="true">
|
||||||
<MudCardContent>
|
<MudCardContent>
|
||||||
@ -27,15 +30,8 @@
|
|||||||
</MudCard>
|
</MudCard>
|
||||||
</MudItem>
|
</MudItem>
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
<MudItem xs="12">
|
|
||||||
<MudText Align="Align.Center" Class="my-8">
|
|
||||||
No data.
|
|
||||||
</MudText>
|
|
||||||
</MudItem>
|
|
||||||
}
|
}
|
||||||
}
|
else if(response.Users.Count != 0)
|
||||||
else
|
|
||||||
{
|
{
|
||||||
@foreach (var user in response.Users)
|
@foreach (var user in response.Users)
|
||||||
{
|
{
|
||||||
@ -52,26 +48,40 @@ else
|
|||||||
</MudCardContent>
|
</MudCardContent>
|
||||||
<MudCardActions>
|
<MudCardActions>
|
||||||
<MudStack Row="true" Style="width:100%" Spacing="4" Justify="Justify.FlexEnd">
|
<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 Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Delete"
|
||||||
<MudButton OnClick="() => NavigateToProfile(user.Baid)" Size="Size.Small" Variant="Variant.Text" StartIcon="@Icons.Material.Filled.Edit" Color="Color.Primary">Edit</MudButton>
|
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>
|
</MudStack>
|
||||||
</MudCardActions>
|
</MudCardActions>
|
||||||
</MudCard>
|
</MudCard>
|
||||||
</MudItem>
|
</MudItem>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<MudItem xs="12">
|
||||||
|
<MudText Align="Align.Center" Class="my-8">
|
||||||
|
No data.
|
||||||
|
</MudText>
|
||||||
|
</MudItem>
|
||||||
|
}
|
||||||
</MudGrid>
|
</MudGrid>
|
||||||
|
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private DashboardResponse? response;
|
private DashboardResponse? response;
|
||||||
private bool isLoading = true;
|
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
{
|
{
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
response = await Client.GetFromJsonAsync<DashboardResponse>("api/Dashboard");
|
||||||
|
|
||||||
isLoading = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -79,4 +89,23 @@ else
|
|||||||
{
|
{
|
||||||
UriHelper.NavigateTo($"/Card/{baid}");
|
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>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.7" />
|
<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="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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user