//Add Location External Id private bool CreateLocationExternalId(FSTLOCN ServiceTradeLocation) { bool success = false; string externalAddr = string.Format(uriStr + "externalid/location/{0}/jde", ServiceTradeLocation.LocationId); //Set cookie string c_settings = "PHPSESSID=" + authorization.AuthToken; //Create request and send to ServiceTrade var client = new RestClient(); client.EndPoint = @externalAddr; client.Method = HttpVerb.POST; client.ContentType = "application/json"; client.SessionCookie = c_settings; client.PostData = string.Format("{{\"value\":\"{0}\"}}", ServiceTradeLocation.External.JdeId); using (var response = client.MakeRequest()) { if (response != null && response.StatusCode == HttpStatusCode.OK) { success = true; response.Close(); } } return(success); }
//location Update public bool UpdateLocation(Location JDE) { bool success = false; var serializer = new JavaScriptSerializer(); FSTLOCN existing_loc = FindLocationServiceTradeId(JDE.slan8); if (existing_loc != null) { JDE.companyId = existing_loc.Company.CompanyId.ToString(); var objAsJsonString = serializer.Serialize(JDE) as String; success = SendLocationUpdate(existing_loc.LocationId, objAsJsonString); } return(success); }
private FSTLOCN FindLocationServiceTradeId(string jdeId) { FSTLOCN loc = null; //Set cookie string c_settings = "PHPSESSID=" + authorization.AuthToken; //Create request and send to ServiceTrade var client = new RestClient(); client.EndPoint = @uriStr + "externalid/location/jde/" + jdeId; client.Method = HttpVerb.GET; client.ContentType = "application/json"; client.SessionCookie = c_settings; using (var response = client.MakeRequest()) { if (response != null && response.StatusCode == HttpStatusCode.OK) { try { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(LocationDataContract)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); LocationDataContract jsonResponse = objResponse as LocationDataContract; loc = jsonResponse.FSTLOCN; } catch (Exception ex) { // log.Error(ex.Message); } response.Close(); } } return(loc); }
//Add new location in Service Trade public bool AddLocation(Location JDE) { bool success = false; //Find the company in service trade int? company_id = FindCompanyServiceTradeId(JDE.slpan8); FSTLOCN existing_loc = FindLocationServiceTradeId(JDE.slan8); if (company_id != null && existing_loc == null) { JDE.companyId = company_id.ToString(); var serializer = new JavaScriptSerializer(); var objAsJsonString = serializer.Serialize(JDE) as String; //Set cookie string c_settings = "PHPSESSID=" + authorization.AuthToken; //Create request and send to ServiceTrade var client = new RestClient(); client.EndPoint = @uriStr + "location"; client.Method = HttpVerb.POST; client.ContentType = "application/json"; client.SessionCookie = c_settings; client.PostData = objAsJsonString; using (var response = client.MakeRequest()) { if (response != null && response.StatusCode == HttpStatusCode.OK) { try { DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(LocationDataContract)); object objResponse = jsonSerializer.ReadObject(response.GetResponseStream()); LocationDataContract jsonResponse = objResponse as LocationDataContract; //Assign the JDE id to the returned Company for further processing if (jsonResponse.FSTLOCN.External.JdeId == string.Empty) { jsonResponse.FSTLOCN.External = new ExternalId() { JdeId = JDE.slan8 }; } success = CreateLocationExternalId(jsonResponse.FSTLOCN); } catch (Exception ex) { // log.Error(ex.Message); } response.Close(); } } } else if (existing_loc != null) { success = true; } return(success); }