@page "/contacts"
@inject NavigationManager NavigationManager
@inject HttpClient Http
Contacts
@{
var contact = context as Contact;
}
@{
var contact = context as Contact;
}
Do you really want to delete @contactToDelete!.NickName
@code {
Contact? contactToDelete;
public List GridData { get; set; } = new List
{
//new Contact
//{
// Id = 1,
// FirstName = "Peter",
// LastName = "Parker",
// NickName = "Spider-Man",
// Place = "New York City",
// DateOfBirth = new DateTime(2001, 8, 1),
// DateCreated = DateTime.Now
//},
//new Contact
//{
// Id = 1,
// FirstName = "Tony",
// LastName = "Stark",
// NickName = "Iron Man",
// Place = "Malibu",
// DateOfBirth = new DateTime(1970, 5, 29),
// DateCreated = DateTime.Now
//},
//new Contact
//{
// Id = 1,
// FirstName = "Bruce",
// LastName = "Wayne",
// NickName = "Batman",
// Place = "Gotham City",
// DateOfBirth = new DateTime(1915, 4, 7),
// DateCreated = DateTime.Now
//}
};
bool showDeleteDialog = false;
protected override async Task OnInitializedAsync()
{
var result = await Http.GetFromJsonAsync>("api/contacts");
if(result is not null)
{
GridData = result;
}
}
void EditContact(int Id)
{
NavigationManager.NavigateTo($"contacts/edit/{Id}");
}
void CreateContact()
{
NavigationManager.NavigateTo($"contacts/new");
}
void DeleteContact(Contact contact)
{
contactToDelete = contact;
showDeleteDialog = true;
}
void CancelDeleteContact()
{
showDeleteDialog = false;
}
async Task ConfirmDeleteContact()
{
if(contactToDelete is null)
{
return;
}
showDeleteDialog = false;
var result = await Http.DeleteAsync($"api/contacts/{contactToDelete.Id}");
if (result.IsSuccessStatusCode)
{
var jsonResult = await result.Content.ReadFromJsonAsync>();
if(jsonResult is not null)
{
GridData = jsonResult;
}
}
}
}