Closed gabrielwedin closed 5 months ago
<AuthorizeView> <Authorized> <button @onclick="RemoveListing" class="px-4 py-2 bg-red-500 text-white rounded hover:bg-red-600">Delete</button> </Authorized> </AuthorizeView> @code { [Parameter] public int ListingID { get; set; } private void RemoveListing() { var listingToDelete = dbContext.Listings.Find(ListingID); if (listingToDelete != null) { dbContext.Listings.Remove(listingToDelete); dbContext.SaveChanges(); } } }
I'd say it looks good. However I'd like to see a warning prompt (delete: yes/no) in case the user accidentally presses the "delete button"
@Samuel-Loof make a comment in the code next time for easier readability.
I did what you asked me to do my friends!
You are comparing a user id to a user name, causing the if statement to never be true. In the following code we got it to work, but it can be done more cleanly with helper methods.
You are comparing a user id to a user name, causing the if statement to never be true. In the following code we got it to work, but it can be done more cleanly with helper methods.
The helper methods are located here:
Specifically this one:
A delete button to delete a listing based on it's ID.