public async Task <IActionResult> Delete(string id) { try { if (string.IsNullOrWhiteSpace(id) || !await tourDAL.IsExistedTourIdAsync(id)) { return(NotFound()); } if (!await tourDAL.HasOrderByTourIdAsync(id)) { if (!await tourDAL.DeleteTourByIdAsync(id)) { ModelState.AddModelError("", "Delete tour failed"); } else { return(RedirectToAction(nameof(Index))); } } else { ModelState.AddModelError("", "Delete failed\nTour already has orders"); } return(RedirectToAction(nameof(Details), new { Id = id })); } catch (Exception ex) { logger.Error(ex.Message); throw; } }