示例#1
0
 public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
 {
     if (KnipperRequestContext.IsError)
     {
         var resp = new HttpResponseMessage(HttpStatusCode.InternalServerError)
         {
             Content      = new StringContent(string.Format("Internal Error")),
             ReasonPhrase = KnipperRequestContext.GetError().ListToString(", ")
         };
         actionExecutedContext.Response = resp;
         //=  actionExecutedContext.Request.CreateErrorResponse(HttpStatusCode.BadRequest, new HttpError(KnipperRequestContext.GetError().ListToString()));
     }
 }
 public static void SafeVoidExecute(Action method)
 {
     try
     {
         method();
     }
     catch (DbEntityValidationException e)
     {
         var newException = new FormattedDbEntityValidationException(e);
         KnipperRequestContext.AddError(newException.Message);
     }
     catch (Exception ex)
     {
         KnipperRequestContext.AddError(ex.Message);
         Log(ex);
     }
 }
        public static T SafeExecute <T>(string a, bool b, string c, Func <string, bool, string, T> method)
        {
            T t = default(T);

            try
            {
                t = method(a, b, c);
            }
            catch (DbEntityValidationException e)
            {
                var newException = new FormattedDbEntityValidationException(e);
                KnipperRequestContext.AddError(newException.Message);
            }
            catch (Exception ex)
            {
                KnipperRequestContext.AddError(ex.Message);
            }
            return(t);
        }
        public static T SafeExecuteWeb <T>(int a, int b, Func <int, int, T> method)
        {
            T t = default(T);

            try
            {
                t = method(a, b);
            }
            catch (DbEntityValidationException e)
            {
                var newException = new FormattedDbEntityValidationException(e);
                KnipperRequestContext.AddError(newException.Message);
            }
            catch (Exception ex)
            {
                KnipperRequestContext.AddError(ex.Message);
                Log(ex);
            }
            return(t);
        }
        public static T SafeExecute <T, K>(K param, Func <K, T> method)
        {
            T t = default(T);

            try
            {
                t = method(param);
            }
            catch (DbEntityValidationException e)
            {
                var newException = new FormattedDbEntityValidationException(e);
                KnipperRequestContext.AddError(newException.Message);
            }
            catch (Exception ex)
            {
                KnipperRequestContext.AddError(ex.Message);
                Log(ex);
            }
            return(t);
        }