예제 #1
0
 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;
 }
예제 #2
0
 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;
 }
예제 #3
0
        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;
        }
예제 #4
0
 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;
 }
예제 #5
0
 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;
 }
예제 #6
0
 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;
 }
예제 #7
0
        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 });
            }
        }