Example #1
0
        public IHttpActionResult Get(int version)
        {
            string entityTypeName = entityHelper.GetEntityTypeName(version, entityName);

            if (!string.IsNullOrEmpty(entityTypeName))
            {
                //return Ok(entityHelper.GetEntityInstance(entityTypeName)); // data contract for object
                var raw = hClient.Submit(version, entityName, Request.Headers) as dynamic;
                if (raw.GetType().GetProperty("Response") != null)
                {
                    if (raw.Response.IsSuccessStatusCode)
                    {
                        var rawObjs = JsonConvert.DeserializeObject(raw.Content.Result);
                        var records = new List <dynamic>();
                        foreach (var rec in rawObjs)
                        {
                            records.Add(entityHelper.MapJsonToObject(rec, entityTypeName));
                        }
                        return(Ok(records));
                    }
                    else
                    {
                        return(raw);
                    }
                }
                else
                {
                    return(raw);
                }
            }
            else
            {
                return(NotFound());
            }
        }
Example #2
0
        public IHttpActionResult Any(int version, dynamic json)
        {
            string entityTypeName = entityHelper.GetEntityTypeName(version, entityName, false);

            if (!string.IsNullOrEmpty(entityTypeName))
            {
                if (json.data != null && json.data.Count > 0)
                {
                    List <dynamic> records = new List <dynamic>();
                    foreach (var item in json.data)
                    {
                        records.Add(entityHelper.MapJsonToObject(item, entityTypeName));
                    }
                    TkWrapper outboundJsonObject = new TkWrapper()
                    {
                        version = version, data = records
                    };

                    return(hClient.Submit(version, entityName, Request.Headers, outboundJsonObject));
                }
                else
                {
                    return(BadRequest("source: TkMiddleware"));
                }
            }
            else
            {
                return(StatusCode(System.Net.HttpStatusCode.NotImplemented));
            }
        }