Exemple #1
0
        public ActionResult GetDataAfterPost(ListPostTerimaOrder listPostTerimaOrder)
        //public ActionResult _TableHasilInput(ListPostTerimaOrder listPostTerimaOrder)
        {
            //Ambil link url di web config
            String url = ConfigurationManager.AppSettings["UrlApi"].ToString();

            String response    = "";
            var    credentials = new NetworkCredential("ac", "123");
            var    handler     = new HttpClientHandler {
                Credentials = credentials
            };                                                                 // for validation

            //    handler.ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return true; };// allow domain checker
            using (var client = new HttpClient(handler))
            {
                // Make your request...
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                try
                {
                    //HttpResponseMessage message = client.GetAsync("https://jsonblob.com/api/b67aac55-90af-11e9-959d-b527025f20cc").Result;
                    HttpResponseMessage message = client.GetAsync(url + "/Api/GetSbu?usrid=Administrator").Result;

                    if (message.IsSuccessStatusCode)
                    {
                        var          serializer = new DataContractJsonSerializer(typeof(List <AfterPostTerimaOrder>));
                        var          result     = message.Content.ReadAsStringAsync().Result;
                        byte[]       byteArray  = Encoding.UTF8.GetBytes(result);
                        MemoryStream stream     = new MemoryStream(byteArray);
                        List <AfterPostTerimaOrder> resultData = serializer.ReadObject(stream) as List <AfterPostTerimaOrder>;

                        ViewBag.ResulData = resultData;
                        return(PartialView("_TableHasilInput"));
                        //====================================================================================
                    }
                    else
                    {
                        ViewBag.error = "Tidak Dapat Respon dari Server";
                        return(PartialView("_TableHasilInput"));
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.error = "Tidak Dapat Respon dari Server";
                    var error = ex.ToString();
                    return(PartialView("_TableHasilInput"));
                }
            }
        }
Exemple #2
0
        //method with no return
        //public void _TableHasilInputNotReal(ListPostTerimaOrder listPostTerimaOrder)
        public ActionResult _TableHasilInput(ListPostTerimaOrder listPostTerimaOrder)
        {
            //Ambil link url di web config
            String url = ConfigurationManager.AppSettings["UrlApi"].ToString();

            String sessionname = Session["userid"].ToString();

            //JIKA PARAMETER NULL digunakan untuk reload setelah delete
            if (listPostTerimaOrder.ModalNmPool != null)
            {
                DateTime now = DateTime.Now;

                listPostTerimaOrder.User = sessionname;

                listPostTerimaOrder.ModalTglAwal = listPostTerimaOrder.ModalTglAwal.Substring(6, 4) + "" + listPostTerimaOrder.ModalTglAwal.Substring(3, 2) + "" + listPostTerimaOrder.ModalTglAwal.Substring(0, 2);

                if (Convert.ToInt64(listPostTerimaOrder.ModalJamAwal) < 10)
                {
                    //listPostTerimaOrder.ModalJamAwal = listPostTerimaOrder.ModalJamAwal.Substring(0, 2) + "" + listPostTerimaOrder.ModalJamAwal.Substring(3, 2);
                    listPostTerimaOrder.ModalJamAwal = "0" + listPostTerimaOrder.ModalJamAwal + "00";
                }
                else
                {
                    listPostTerimaOrder.ModalJamAwal = listPostTerimaOrder.ModalJamAwal + "00";
                }


                listPostTerimaOrder.ModalTglAkhir = listPostTerimaOrder.ModalTglAkhir.Substring(6, 4) + "" + listPostTerimaOrder.ModalTglAkhir.Substring(3, 2) + "" + listPostTerimaOrder.ModalTglAkhir.Substring(0, 2);

                if (Convert.ToInt64(listPostTerimaOrder.ModalJamAkhir) < 10)
                {
                    //listPostTerimaOrder.ModalJamAkhir = listPostTerimaOrder.ModalJamAkhir.Substring(0, 2) + "" + listPostTerimaOrder.ModalJamAkhir.Substring(3, 2);
                    listPostTerimaOrder.ModalJamAkhir = "0" + listPostTerimaOrder.ModalJamAkhir + "00";
                }
                else
                {
                    listPostTerimaOrder.ModalJamAkhir = listPostTerimaOrder.ModalJamAkhir + "00";
                }


                var datenow = now.ToString("yyyyMMdd");
                var timenow = now.ToString("HHmm");
                listPostTerimaOrder.TglTrans = datenow;
                listPostTerimaOrder.JamTrans = timenow;

                ParamPostTerimaOrder postTerimaOrder = new ParamPostTerimaOrder()
                {
                    userid    = listPostTerimaOrder.User,
                    jenis     = listPostTerimaOrder.ModalJenis,
                    pool      = listPostTerimaOrder.ModalNmPool,
                    tglawal   = listPostTerimaOrder.ModalTglAwal,
                    jamawal   = listPostTerimaOrder.ModalJamAwal,
                    tglakhir  = listPostTerimaOrder.ModalTglAkhir,
                    jamakhir  = listPostTerimaOrder.ModalJamAkhir,
                    jumlah    = listPostTerimaOrder.ModalJmlBus,
                    tgltrans  = listPostTerimaOrder.TglTrans,
                    jamtrans  = listPostTerimaOrder.JamTrans,
                    keltujuan = listPostTerimaOrder.ModalKelTujuan,
                    ac        = "Y"
                };

                var json2         = new JavaScriptSerializer().Serialize(postTerimaOrder);
                var stringPayload = JsonConvert.SerializeObject(postTerimaOrder);
                //String response = "";
                var credentials = new NetworkCredential("username", "password");
                var handler     = new HttpClientHandler {
                    Credentials = credentials
                };
                var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json");
                using (var client = new HttpClient(handler))
                {
                    try
                    {
                        HttpResponseMessage message = client.PostAsync(url + "/api/GetStock", httpContent).Result;
                        if (message.IsSuccessStatusCode)
                        {
                            //Action jika mendapat balasan sukses dari post api, panggil method GetDataAfterPost
                            //GetDataAfterPost(listPostTerimaOrder);

                            //=====================================================================
                            String response     = "";
                            var    credentials2 = new NetworkCredential("ac", "123");
                            var    handler2     = new HttpClientHandler {
                                Credentials = credentials2
                            };
                            using (var client2 = new HttpClient(handler2))
                            {
                                // Make your request...
                                client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                                try
                                {
                                    //HttpResponseMessage message = client.GetAsync("https://jsonblob.com/api/b67aac55-90af-11e9-959d-b527025f20cc").Result;
                                    HttpResponseMessage message2 = client2.GetAsync(url + "/Api/GetSbu?usrid=" + sessionname).Result;

                                    if (message2.IsSuccessStatusCode)
                                    {
                                        var          serializer = new DataContractJsonSerializer(typeof(List <AfterPostTerimaOrder>));
                                        var          result     = message2.Content.ReadAsStringAsync().Result;
                                        byte[]       byteArray  = Encoding.UTF8.GetBytes(result);
                                        MemoryStream stream     = new MemoryStream(byteArray);
                                        List <AfterPostTerimaOrder> resultData = serializer.ReadObject(stream) as List <AfterPostTerimaOrder>;

                                        ViewBag.ResulData = resultData;
                                        return(PartialView("_TableHasilInput"));
                                        //====================================================================================
                                    }
                                    else
                                    {
                                        ViewBag.error = "Tidak Dapat Respon dari Server";
                                        return(PartialView("_TableHasilInput"));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ViewBag.error = "Tidak Dapat Respon dari Server";
                                    var error = ex.ToString();
                                    return(PartialView("_TableHasilInput"));
                                }
                            }
                            //=====================================================================
                        }
                        else
                        {
                            return(PartialView("_TableHasilInput"));
                        }
                    }
                    catch
                    {
                        return(PartialView("_TableHasilInput"));
                    }
                }
            }
            else
            {
                //=====================================================================
                String response     = "";
                var    credentials2 = new NetworkCredential("ac", "123");
                var    handler2     = new HttpClientHandler {
                    Credentials = credentials2
                };
                using (var client2 = new HttpClient(handler2))
                {
                    // Make your request...
                    client2.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    try
                    {
                        //HttpResponseMessage message = client.GetAsync("https://jsonblob.com/api/b67aac55-90af-11e9-959d-b527025f20cc").Result;
                        HttpResponseMessage message2 = client2.GetAsync(url + "/Api/GetSbu?usrid=" + sessionname).Result;

                        if (message2.IsSuccessStatusCode)
                        {
                            var          serializer = new DataContractJsonSerializer(typeof(List <AfterPostTerimaOrder>));
                            var          result     = message2.Content.ReadAsStringAsync().Result;
                            byte[]       byteArray  = Encoding.UTF8.GetBytes(result);
                            MemoryStream stream     = new MemoryStream(byteArray);
                            List <AfterPostTerimaOrder> resultData = serializer.ReadObject(stream) as List <AfterPostTerimaOrder>;

                            ViewBag.ResulData = resultData;
                            return(PartialView("_TableHasilInput"));
                            //====================================================================================
                        }
                        else
                        {
                            ViewBag.error = "Tidak Dapat Respon dari Server";
                            return(PartialView("_TableHasilInput"));
                        }
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error = "Tidak Dapat Respon dari Server";
                        var error = ex.ToString();
                        return(PartialView("_TableHasilInput"));
                    }
                }
                //=====================================================================
            }
        }