public void SetTest()
 {
     var a = new PilkadaAPI();
     var pilkadaModel = new PilkadaModel
     {
         id = new Guid("115682e1-e390-50f0-ad72-feaf9afe425c"),
         jenis = 1, nama = "KAB. SUMEDANG"
     };
     var b = a.Set(pilkadaModel);
     Assert.AreEqual(b.response.msg.ToLower(), "ok");
 }
        public JsonResponse<BaseResponse> Set(PilkadaModel pilkadaModel)
        {
            var url = ConfigurationManager.AppSettings["BaseAPIUrl"];
            var request = (HttpWebRequest)WebRequest.Create(url + @"pilkada/set");

            var postData = "&key=sdwqe3Xq75pc";
            postData += "&id=" + (pilkadaModel.id.ToString().Equals("00000000-0000-0000-0000-000000000000") ? "" : pilkadaModel.id.ToString());
                postData += "&prov_id=f8da2cd5-f3d3-540d-bddb-b8cf59cbab5c";
                postData += "&ket=" + pilkadaModel.nama;
            var data = Encoding.ASCII.GetBytes(postData);

            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            var response = (HttpWebResponse)request.GetResponse();

            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            var jsonResponse = JsonConvert.DeserializeObject<JsonResponse<BaseResponse>>(responseString);
            if (jsonResponse.response != null && jsonResponse.response.msg.ToLower().Equals("ok"))
            {
                return jsonResponse;
            }
            throw new Exception(jsonResponse.response != null ? jsonResponse.response.msg : "Error On Submit Pilkada" );
            //using (var client = new HttpClient())
            //{
            //    client.BaseAddress = new Uri(url);
            //    HttpContent content = new StringContent(JsonConvert.SerializeObject(pilkadaModel));
            //    //content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            //    using (var response = client.PostAsync(@"pilkada/set", content).Result)
            //    {
            //        if (!response.IsSuccessStatusCode) throw new Exception(response.RequestMessage.ToString());
            //        var productJsonString = response.Content.ReadAsStringAsync();

            //        return
            //            JsonConvert.DeserializeObject<JsonResponse<PilkadaResponse>>(productJsonString.Result);
            //    }
            //}
        }