public async Task <IActionResult> DeleteConfirmed(int?id) { try { _partnerFactory.DeletePartner(id); return(RedirectToAction(nameof(Index))); } catch (InvalidOperationException e) { // log error here var allowedErrors = new List <string>() { ServicesConstants.DeletePartner_NotAllowedReasonMessage_PartnerHasActions, ServicesConstants.DeletePartner_NotAllowedReasonMessage_PartnerHasUsedActions, ServicesConstants.DeletePartner_NotAllowedReasonMessage_PartnerHasUsers }; if (allowedErrors.Contains(e.Message ?? "")) { return(View("CustomError", new CustomErrorViewModel() { HeaderMessage = "Not allowed", Message = e.Message, ReturnUrls = new Dictionary <string, string>() { { "Back to Delete Partner page", Url.Action("Delete", "Partners", new { area = "Admin", id = id }) }, { "Go to this Partner details", Url.Action("Details", "Partners", new { area = "Admin", id = id }) }, { "Go to Partners", Url.Action("Index", "Partners", new { area = "Admin" }) }, } })); } else { return(RedirectToAction(nameof(Index))); } } catch (Exception e) { // log error here return(RedirectToAction(nameof(Index))); } }