@using Shared.Dto.Api @using Throw @inject HttpClient Client @if (!Data.IsFavorite) { Add to favorite? } else { Remove from favorite? } Cancel Confirm @code{ [CascadingParameter] public required MudDialogInstance MudDialog { get; set; } [Parameter] public required SongPlayRecord Data { get; set; } [Parameter] public long CardId { get; set; } private async Task Submit() { var favoriteData = new MusicFavoriteDto { CardId = CardId, IsFavorite = !Data.IsFavorite, MusicId = Data.MusicId }; var response = await Client.PostAsJsonAsync("api/Profiles/SetFavorite", favoriteData); var result = await response.Content.ReadFromJsonAsync>(); result.ThrowIfNull(); MudDialog.Close(DialogResult.Ok(result)); } private void Cancel() => MudDialog.Cancel(); }