public static bool Delete(int id, out ResponseMessage responseMessage) { Uri uri = new Uri(String.Format("{0}/ClientAccess/Close?id={1}", OdataServiceUri, id)); string json = String.Empty;//String.Format("{{\"id\":{0}}}",id); bool result = PostJson(uri, json, out responseMessage); return result; }
public bool Save(out ResponseMessage responseMessage) { Uri uri = new Uri(String.Format("{0}/Classifier/SaveAttributes", OdataServiceUri)); string json = JsonConvert.SerializeObject(this); bool result = PostJson(uri, json, out responseMessage); return result; }
protected static bool PostJson(Uri uri, string json, out ResponseMessage responseMessage) { var request = (HttpWebRequest)WebRequest.Create(uri); CredentialCache cc = new CredentialCache(); cc.Add(uri, "NTLM", CredentialCache.DefaultNetworkCredentials); request.Credentials = cc; //request.Headers.Add("Authorization", AuthorizationHeaderValue); request.ContentType = "text/json"; request.Method = "POST"; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var response = (HttpWebResponse)request.GetResponse(); using (var streamReader = new StreamReader(response.GetResponseStream())) { string responseContent = streamReader.ReadToEnd(); responseMessage = JsonConvert.DeserializeObject<ResponseMessage>(responseContent); } return response.StatusCode == HttpStatusCode.Created; }
public static bool SaveFromExcel(byte[] data, out ResponseMessage responseMessage) { Uri uri = new Uri(String.Format("{0}/Classifier/SaveFromExcel", OdataServiceUri)); string json = JsonConvert.SerializeObject(data); bool result = PostJson(uri, json, out responseMessage); return result; }
public bool GoBack(out ResponseMessage responseMessage) { Uri uri = new Uri(String.Format("{0}/Claim/GoBack", OdataServiceUri)); string json = JsonConvert.SerializeObject(this); bool result = PostJson(uri, json, out responseMessage); return result; }
public bool Save(out ResponseMessage responseMessage) { Uri uri = new Uri(String.Format("{0}/Claim/Save", OdataServiceUri)); string json = JsonConvert.SerializeObject(this); //var content = new StringContent(json, Encoding.UTF8, "application/json"); //var response = GetApiClientAsync().PostAsync(uri, content).Result; bool result = PostJson(uri, json, out responseMessage); //var response = DeserializeResponse(); return result; }
public ActionResult ServiceSheetTechForm(Claim model) { try { ResponseMessage responseMessage = null; bool complete = false; if (!String.IsNullOrEmpty(Request.Form["ServiceSheetSave"])) { complete = model.Go(out responseMessage); } else if (!String.IsNullOrEmpty(Request.Form["ServiceSheetCancel"])) { complete = model.GoBack(out responseMessage); return RedirectToAction("Index"); } if (responseMessage == null)responseMessage = new ResponseMessage(); if (!complete) throw new Exception(responseMessage.ErrorMessage); return RedirectToAction("List"); } catch (Exception ex) { TempData["error"] = ex.Message; return RedirectToAction("Index", new { id = model.Id }); } }