//protected T GetJContainerResult<T>(string strResponse) where T : JContainer //{ // JObject result = (JObject)JsonConvert.DeserializeObject(strResponse); // if (result == null || (string)result["Status"] != "Success") // { // return default(T); // } // return (T)result["Data"]; //} public TResult AjaxAsync <TResult, TPostData>(string url, TPostData jsonData, RequestType requestType, Func <HttpClient, Func <HttpResponseMessage, TResult>, TResult> ajaxAsyncDelegate, AuthenticationHeaderValue authenticationHeaderValue = null) where TResult : class { SetDefaultAuthorizationHeaderValue(ref authenticationHeaderValue); using (HttpClient client = SingleInstanceHelper.GetInstance <HttpClient>()) { client.BaseAddress = new Uri(GetBaseUrl()); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); if (authenticationHeaderValue != null) { client.DefaultRequestHeaders.Authorization = authenticationHeaderValue; } return(ajaxAsyncDelegate(client, response => { string strResponseBody = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == HttpStatusCode.OK) { return SerializationHelper.JsonToObject <TResult>(strResponseBody); } else { LogHelper.Info(strResponseBody); } return default(TResult); })); } }
protected void ResetDbContext() { Dispose(); db = SingleInstanceHelper.GetInstance <TDbContext>(true); }