Example #1
0
        private Task HandleSuccessRequestAsync(HttpContext context, object body, int code)
        {
            string jsonString = string.Empty;

            var bodyText = !body.ToString().IsValidJson() ? ConvertToJSONString(body) : body.ToString();

            dynamic bodyContent = JsonConvert.DeserializeObject <dynamic>(bodyText);
            Type    type        = bodyContent?.GetType();

            if (type.Equals(typeof(Newtonsoft.Json.Linq.JObject)))
            {
                Wrappers.ApiResponse apiResponse = JsonConvert.DeserializeObject <Wrappers.ApiResponse>(bodyText);
                if ((apiResponse.StatusCode != code || apiResponse.Result != null) ||
                    (apiResponse.StatusCode == code && apiResponse.Result == null))
                {
                    jsonString = ConvertToJSONString(GetSucessResponse(apiResponse));
                }
                else
                {
                    jsonString = ConvertToJSONString(code, bodyContent);
                }
            }
            else
            {
                jsonString = ConvertToJSONString(code, bodyContent);
            }

            context.Response.ContentType = "application/json";
            return(context.Response.WriteAsync(jsonString));
        }
Example #2
0
        private Wrappers.ApiResponse GetSucessResponse(Wrappers.ApiResponse apiResponse)
        {
            if (apiResponse.Version.Equals("1.0.0.0"))
            {
                apiResponse.Version = GetApiVersion();
            }

            return(apiResponse);
        }
Example #3
0
 private string ConvertToJSONString(Wrappers.ApiResponse apiResponse)
 {
     return(JsonConvert.SerializeObject(apiResponse, JSONSettings()));
 }