Ejemplo n.º 1
0
        public async Task <InvoiceResponse> PushInvoiceToRDCBrains(InvoiceRequest request)
        {
            _handler = new MyHttpClientHandler.MyHandler();
            Client   = new HttpClient();
            var byteArray = Encoding.ASCII.GetBytes("ADDA:test");

            Client.BaseAddress = new Uri("http://35.185.72.232/");
            Client.DefaultRequestHeaders.Accept.Clear();
            //Client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            var response = new InvoiceResponse();
            var result   = await Client.PostAsJsonAsync("RDCWebServices/RDCPush.jsp", request);

            if (result.IsSuccessStatusCode)
            {
                var resultasstring = await result.Content.ReadAsStringAsync();

                response = JsonConvert.DeserializeObject <InvoiceResponse>(resultasstring);
            }
            else
            {
                response = DummyResponse();
            }
            return(response);
        }
        public async Task <IHttpActionResult> Post(InvoiceRequest request)
        {
            try
            {
                if (request == null)
                {
                    return(BadRequest());
                }
                InvoiceRepository _repository = new InvoiceRepository();
                InvoiceResponse   response    = await _repository.PushInvoiceToRDCBrains(request);

                if (response.statusCode == "0")
                {
                    Dictionary <string, string> jsonresponse = new Dictionary <string, string>();
                    jsonresponse["Bill Number"] = response.Bill_Number;
                    jsonresponse["freeFormRSN"] = response.freeFormRSN;
                    jsonresponse["peopleRSN"]   = response.peopleRSN;
                    jsonresponse["folderRSN"]   = response.folderRSN;
                    jsonresponse["statusCode"]  = response.statusCode;
                    jsonresponse["status"]      = response.status;
                    return(Created(Request.RequestUri, jsonresponse));
                }
                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Ejemplo n.º 3
0
        public async Task <InvoiceResponse> PushInvoiceToRDCBrains(InvoiceRequest request)
        {
            _handler = new MyHttpClientHandler.MyHandler();
            Client   = new HttpClient();
            var byteArray = Encoding.ASCII.GetBytes("ADDA:test");

            Client.BaseAddress = new Uri("http://35.185.72.232/");
            Client.DefaultRequestHeaders.Accept.Clear();
            //Client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            // Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            var response = new InvoiceResponse();
            var json     = new JavaScriptSerializer().Serialize(request);
            //HttpRequestMessage requestss = new HttpRequestMessage(HttpMethod.Post, "RDCWebServices/RDCPush.jsp");
            //requestss.Content = new StringContent(json, Encoding.UTF8, "application/json");
            //var sss = Client.SendAsync(requestss).Result;
            //if (sss.IsSuccessStatusCode)
            //{
            //    var stringsd = sss.Content.ReadAsStringAsync();
            //}
            //HttpContent _Body = new StringContent(json);
            //// and add the header to this object instance
            //// optional: add a formatter option to it as well
            //_Body.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            //// synchronous request without the need for .ContinueWith() or await
            //HttpResponseMessage  asresponse = Client.PostAsync("RDCWebServices/RDCPush.jsp", _Body).Result;
            //if (asresponse.IsSuccessStatusCode)
            //{
            //    var resresultasstring = await asresponse.Content.ReadAsStringAsync();
            //}
            var result = await Client.PostAsJsonAsync("RDCWebServices/RDCPush.jsp", request);

            if (result.IsSuccessStatusCode)
            {
                var resultasstring = await result.Content.ReadAsStringAsync();

                //dynamic obj = JsonConvert.DeserializeObject<dynamic>(resultasstring);
                // object objs = resultasstring;
                //string responsestring = JsonConvert.DeserializeObject<string>(resultasstring);
                JObject s = JObject.Parse(resultasstring);
                response.Bill_Number = (string)s["Bill Number"];
                response.folderRSN   = (string)s["folderRSN"];
                response.freeFormRSN = (string)s["freeFormRSN"];
                response.peopleRSN   = (string)s["peopleRSN"];
                response.status      = (string)s["status"];
                response.statusCode  = (string)s["statusCode"];
                //  response = JsonConvert.DeserializeObject<InvoiceResponse>(resultasstring);
            }
            else
            {
                response = DummyResponse();
            }
            return(response);
        }
        private InvoiceResponse DummyResponse()
        {
            InvoiceResponse response = new InvoiceResponse();

            response.Bill_Number = "Payment Reference generated";
            response.peopleRSN   = "025";
            response.folderRSN   = "310007680995";
            response.statusCode  = "310007680995";
            response.status      = "310007680995";
            return(response);
        }
        public async Task <InvoiceResponse> PushInvoiceToRDCBrains(InvoiceRequest request)
        {
            _handler = new MyHttpClientHandler.MyHandler();
            Client   = new HttpClient();
            var byteArray = Encoding.ASCII.GetBytes("ADDA:test");

            Client.BaseAddress = new Uri("http://35.185.72.232/");
            Client.DefaultRequestHeaders.Accept.Clear();
            //Client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            // Client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");
            Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
            var         response = new InvoiceResponse();
            var         json     = new JavaScriptSerializer().Serialize(request);
            HttpContent _Body    = new StringContent(json);

            // and add the header to this object instance
            // optional: add a formatter option to it as well
            _Body.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            // synchronous request without the need for .ContinueWith() or await
            HttpResponseMessage asresponse = Client.PostAsync("RDCWebServices/RDCPush.jsp", _Body).Result;

            if (asresponse.IsSuccessStatusCode)
            {
                var resresultasstring = await asresponse.Content.ReadAsStringAsync();
            }
            var result = await Client.PostAsJsonAsync("RDCWebServices/RDCPush.jsp", request);

            if (result.IsSuccessStatusCode)
            {
                var resultasstring = await result.Content.ReadAsStringAsync();

                response = JsonConvert.DeserializeObject <InvoiceResponse>(resultasstring);
            }
            else
            {
                response = DummyResponse();
            }
            return(response);
        }
        public async Task <IHttpActionResult> Post(InvoiceRequest request)
        {
            try
            {
                if (request == null)
                {
                    return(BadRequest());
                }
                InvoiceRepository _repository = new InvoiceRepository();
                InvoiceResponse   response    = await _repository.PushInvoiceToRDCBrains(request);

                if (response.statusCode == "025")
                {
                    return(Created <InvoiceResponse>(Request.RequestUri, response));
                }
                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }