예제 #1
0
        [HttpGet("{subPath}/Md/{fieldId}")] //IEnumerable<AxEnum>
        public object Get(String subPath, String fieldId, [FromQuery] IntervalParameters parameters)
        {
            ICommonError err = errorBuilder.Success("");
            object       ret;

            var uri = this.HttpContext.Request.Path.ToUriComponent();

            if (uri.Substring(uri.Length - 3) == "/Md")
            {
                var md = contextHelper.GetMetadata(context, subPath) as IMetadataBase <object, string>;
                ret = (md != null) ? mdHelper.GetMetadataByQuery(this.Request.Query, md) : this.BadReqErr("Resource [" + subPath + "] not found");
            }
            else if (fieldId != null)
            {
                var md = contextHelper.GetMetadataField(context, subPath, fieldId) as IMetadataBase <object, string>;
                ret = (md != null) ? mdHelper.GetMetadataByQuery(this.Request.Query, md) : this.BadReqErr("Resource [" + subPath + "] not found");
            }
            else
            {
                if (this.Request.Query.Count > 0)
                {
                    object[] par  = { contextHelper.ToKeyValuePairFromRequest(this.Request) };
                    var      resp = contextHelper.InvokeReaderMethod(context, subPath, "Get", par);
                    ret = resp ?? this.BadReqErr("Resource [" + subPath + "] not found");
                }
                else
                {
                    var resp = contextHelper.InvokeReaderMethod(context, subPath, "GetAll");
                    ret = resp ?? this.BadReqErr("Resource [" + subPath + "] not found");
                }
            }
            return(ret);
        }
예제 #2
0
        // Build Error
        private ICommonError BadReqErr(string msg)
        {
            ICommonError err = errorBuilder.ClientError("Bad Request: " + msg);

            err.StatusCode = 400;
            //err.Message = msg;
            errorBuilder.EerectTo(err, this.Response);
            return(err);
        }
예제 #3
0
        protected static string ToJson(ICommonError err)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("{");
            sb.AppendLine("\"name\":\"" + err.Name + "\",");
            sb.AppendLine("\"message\":\"" + err.Message + "\",");
            sb.AppendLine("\"code\":" + err.Code.ToString() + ",");
            sb.AppendLine("\"statusCode\":" + err.StatusCode.ToString() + "");
            sb.AppendLine("}");
            return(sb.ToString());
        }
예제 #4
0
        public object Post([FromBody] NVASD_Incoming value)
        {
            ICommonError err = _errorBuilder.Success("");
            object       ret;

            if (value != null)
            {
                _context.NvaSdIncoming.Access.Inserter.Add(value);
                var rt = _context.Save();

                if (rt != null && rt != "")
                {
                    err            = _errorBuilder.ClientError(rt);
                    err.Name       = "Unprocessable Entity";
                    err.StatusCode = 422;
                    _errorBuilder.EerectTo(err, this.Response);
                    ret = err;
                }
                else
                {
                    ret = _context.NvaSdIncoming.Access.Reader.Find(value.ID);
                }
            }
            else
            {
                //this.Response.Body.Position = 0;
                var s = "";
                if (this.Request.Body.Length > 0)
                {
                    this.Request.Body.Position = 0;
                    s = new StreamReader(this.Request.Body, Encoding.UTF8).ReadToEnd();
                }

                err            = _errorBuilder.ClientError("Bad Request");
                err.StatusCode = 400;

                err.Message = string.IsNullOrEmpty(s) ?  "Incoming data is empty" : "Incoming data is bad: [" + s + "]";
                _errorBuilder.EerectTo(err, this.Response);
                ret = err;
            }

            return(ret);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="commonError"></param>
 /// <param name="errMsg"></param>
 public BusinessException(ICommonError commonError, string errMsg) : base()
 {
     this.commonError = commonError;
     this.commonError.SetErrMsg(errMsg);
 }
 /// <summary>
 /// 直接接收EmBusinessError的传参用于构造业务异常
 /// </summary>
 /// <param name="commonError"></param>
 public BusinessException(ICommonError commonError) : base()
 {
     this.commonError = commonError;
 }
예제 #7
0
 public static Resp <T> End(ICommonError value) => new Resp <T>(value);
예제 #8
0
 private Resp(ICommonError responce)
 {
     resp = responce;
 }
예제 #9
0
 public string ToJsonString(ICommonError err) => ToJson(err);
예제 #10
0
 public void EerectTo(ICommonError error, TTarget targetObj)
 {
     ErectFunc(error, targetObj);
 }