コード例 #1
0
        protected IHttpActionResult ExecuteRequest(Func <IHttpActionResult> function)
        {
            if (!ModelState.IsValid)
            {
                var errors = GetValidationErrors();
                LogWarningObjectToJson(errors);
                var jsonErrors = JsonConvert.SerializeObject(errors);
                return(BadRequest(jsonErrors));
            }

            IHttpActionResult actionResult = null;

            try
            {
                actionResult = function.Invoke();
            }
            catch (DbUpdateException ex)
            {
                LoggerService.ErrorException(ex, "Error during dataBase action");
                actionResult = BadRequest(ex.InnerException.Message);
            }
            catch (Exception ex)
            {
                LoggerService.ErrorException(ex, "Request Error");
                actionResult = InternalServerError(ex);
            }

            return(actionResult);
        }