public IActionResult OnPost() { _logger.LogInformation($"DeleteReview OnPost() called. ReviewId = '{ReviewId}'."); if (ReviewId == null) { return(NotFound()); } // Find the review in the database Review r = _context.Review.Find(ReviewId); if (r != null) { _context.Review.Remove(r); // Delete the review _context.SaveChanges(); } return(RedirectToPage("./Index")); }
// Extra Credit Version 1: When user clicks Delete Review button. This is what executes // async Task<IActionResult> ==> Asynchronous // IActionResult ==> Syncronous public IActionResult OnPostDeleteReviewAsync(int?id) { if (!ModelState.IsValid) { _logger.LogWarning($"OnPostDeleteReview() invalid model."); return(Page()); } _logger.LogWarning($"OnPostDeleteReview() called. Movie Id {id}. Review Id {ReviewIdToDelete}"); // Find the review in the database Review Review = _context.Review.FirstOrDefault(r => r.ID == ReviewIdToDelete); if (Review != null) { _context.Remove(Review); // Delete the review _context.SaveChanges(); } Movie = _context.Movie.Include(m => m.Reviews).FirstOrDefault(m => m.ID == id); return(Page()); }