public override void OnActionExecuting(HttpActionContext actionContext)
        {
            string modelName;

            if (!canModelNull && IsModelNull(actionContext.ActionArguments, out modelName))
            {
                var back = new HttpBackResult <string> {
                    Status = (int)HttpBackCode.Parameter, Msg = $"参数\"{modelName}\"不可为空", Data = null
                };
                actionContext.Response         = new HttpResponseMessage(HttpStatusCode.OK);
                actionContext.Response.Content = new StringContent(back.ToJson());
                return;
            }

            if (!actionContext.ModelState.IsValid)
            {
                var back = new HttpBackResult <string> {
                    Status = (int)HttpBackCode.Parameter, Msg = actionContext.ModelState.GetErrorMessage(), Data = null
                };
                actionContext.Response         = new HttpResponseMessage(HttpStatusCode.OK);
                actionContext.Response.Content = new StringContent(back.ToJson());
            }
            else
            {
                base.OnActionExecuting(actionContext);
            }
        }
Пример #2
0
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            var back = new HttpBackResult <string> {
                Status = (int)HttpBackCode.Parameter, Msg = actionExecutedContext.Exception.Message, Data = null
            };

            actionExecutedContext.Response         = new HttpResponseMessage(HttpStatusCode.OK);
            actionExecutedContext.Response.Content = new StringContent(back.ToJson());
        }
Пример #3
0
        public HttpBackResult <string> Patch(int id)
        {
            //return this.CreateResponseMessage(HttpBackCode.Success, new { Name = "yyg", Age = age });

            var back = new HttpBackResult <string> {
                Status = 2, Data = "yyg", Msg = "成功"
            };

            return(back);
        }