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)); }
private Wrappers.ApiResponse GetSucessResponse(Wrappers.ApiResponse apiResponse) { if (apiResponse.Version.Equals("1.0.0.0")) { apiResponse.Version = GetApiVersion(); } return(apiResponse); }
private string ConvertToJSONString(Wrappers.ApiResponse apiResponse) { return(JsonConvert.SerializeObject(apiResponse, JSONSettings())); }