Example #1
0
        public static SOResult SetDetailsRest(string token, string problemCategory, string problemSubcategory, string otherDetails, string customerComments, string firstName,
                                              string lastName, string email, string phone1, string address, string city, string xcoordinate, string ycoordinate, string resolvedAddress,
                                              string locality, string neighborhood, string postal_code, string route, string street_number, string image)
        {
            var scriptServer = WebConfigurationManager.AppSettings["constServer"] + "/v4/scripts/SO_SET_RECORD";

            var serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = int.MaxValue;

            var serializedResult = serializer.Serialize(new Dictionary <string, string>
            {
                ["problemCategory"]    = problemCategory,
                ["problemSubcategory"] = problemSubcategory,
                ["otherDetails"]       = otherDetails,
                ["customerComments"]   = customerComments,
                ["firstName"]          = firstName,
                ["lastName"]           = lastName,
                ["email"]           = email,
                ["phone1"]          = phone1,
                ["address"]         = !string.IsNullOrWhiteSpace(address) ? address : string.Empty,
                ["city"]            = !string.IsNullOrWhiteSpace(city) ? city : string.Empty,
                ["xcoordinate"]     = xcoordinate,
                ["ycoordinate"]     = ycoordinate,
                ["resolvedAddress"] = resolvedAddress,
                //["refaddressid"] = refaddressid,
                ["locality"]      = locality,
                ["neighborhood"]  = neighborhood,
                ["postal_code"]   = postal_code,
                ["route"]         = route,
                ["street_number"] = street_number,
                ["base64String"]  = image
            });

            var client  = new RestClient(scriptServer);
            var request = new RestRequest(Method.POST);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("authorization", token);
            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json", serializedResult, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            Message message = serializer.Deserialize <Message>(response.Content);

            log.Info("In SetDetailsRest response Message: " + message.result.Message + " status: " + message.status + " code: " + message.code + " err_message: " + message.message);

            if (message.status == 200)
            {
                string   soResultData = message.result.Message;
                SOResult soResult     = getSOResult(soResultData);
                //soResult.token = token;
                soResult.Message = "OK";
                return(soResult);
            }
            return(null);
        }
Example #2
0
        public static SOResult getSOResult(string output)
        {
            SOResult soresult = new SOResult();
            var      ser      = new DataContractJsonSerializer(typeof(SOResult));

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(output)))
            {
                soresult = (SOResult)ser.ReadObject(ms);
            }
            return(soresult);
        }