コード例 #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
        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);
        }