/// <summary> /// Runs the action, logs an error and returns boolMessageEx that wraps up all there values. /// Bool flag for successful call without excpetion, errorMessage if there was an exception, /// and the exception itself if it occurred. /// </summary> /// <param name="message">Success message</param> /// <param name="errorMessage">Failure message</param> /// <param name="action">Action to run</param> /// <returns>Error message.</returns> public static BoolMessageEx GetBoolResultEx(string message, string errorMessage, Func <BoolMessageEx> action) { BoolMessageEx result = action(); string finalmessage = message; if (!result.Success) { finalmessage = string.IsNullOrEmpty(errorMessage) ? result.Message : errorMessage; } return(new BoolMessageEx(result.Success, result.Ex, finalmessage)); }
/// <summary> /// Runs the action, logs an error and returns boolMessageEx that wraps up all there values. /// Bool flag for successful call without excpetion, errorMessage if there was an exception, /// and the exception itself if it occurred. /// </summary> /// <param name="message">Success message</param> /// <param name="errorMessage">Failure message</param> /// <param name="action">Action to run</param> /// <returns>Error message.</returns> public static BoolMessageEx CatchLogReturnBoolResultEx(string message, string errorMessage, Func <BoolMessageEx> action) { string finalMessage = message; bool success = false; BoolMessageEx result = null; Exception ex = null; try { result = action(); ex = result.Ex; success = result.Success; finalMessage = result.Message; } catch (Exception exception) { success = false; ex = exception; finalMessage = errorMessage; _logger.Error(exception, null, null); } return(new BoolMessageEx(success, ex, finalMessage)); }