public static BaseWebApiResult ConvertToWebApiResult(this BaseResult result) { BaseWebApiResult webApiResult = new BaseWebApiResult(); switch (result.ResultType) { case ResultType.INFO: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.BadRequest; break; case ResultType.ERROR: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.InternalServerError; break; case ResultType.SUCCESS: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.OK; break; case ResultType.WARNING: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.NotFound; break; default: break; } return(webApiResult); }
public static BaseWebApiResult ConvertToWebApiResult(this BaseResult result, ILoggerManager logger) { BaseWebApiResult webApiResult = new BaseWebApiResult(); switch (result.ResultType) { case ResultType.INFO: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.BadRequest; logger.LogInfo(result.Message); break; case ResultType.ERROR: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.InternalServerError; // Superseded because the previous method did not set the trace exception logger.Log(LogType.ERROR, result.DetailException); //logger.LogError(result.Message, result.DetailException); break; case ResultType.SUCCESS: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.OK; logger.LogInfo(result.Message); break; case ResultType.WARNING: webApiResult.Message = result.Message; webApiResult.ResponseCode = HttpStatusCode.NotFound; logger.LogWarn(result.Message); break; default: break; } return(webApiResult); }