Example #1
0
        static void PostJson()
        {
            int     day;
            Decimal milk;
            int     skins;

            Console.WriteLine("Order for day?");
            string dayInput = Console.ReadLine();

            Console.WriteLine("Customer?");
            string customer = Console.ReadLine();

            Console.WriteLine("Quantity of Milk?");
            string milkInput = Console.ReadLine();

            Console.WriteLine("Quantity of Skins?");
            string skinsInput = Console.ReadLine();

            if (int.TryParse(dayInput, out day) && Decimal.TryParse(milkInput, out milk) && int.TryParse(skinsInput, out skins))
            {
                OrderBO.JsonRequest req = new OrderBO.JsonRequest(customer, milk, skins);

                var json     = RestHelper.ConvertObjectToJason(req);
                var response = RestHelper.Post("http://localhost:51190/", "sheep_shop/orderConsole/" + day.ToString(), json);
//                System.Console.WriteLine(string.Format("Status Code {0}", response.StatusCode));
                if (response.ErrorMessage != null)
                {
                    System.Console.WriteLine(string.Format("Error Message {0}", response.ErrorMessage));
                }
                else if (response.StatusCode.ToString() != "OK")
                {
                    System.Console.WriteLine(JValue.Parse(response.Content.ToString()).ToString(Newtonsoft.Json.Formatting.Indented));
                }
                else
                {
                    var resObj = RestHelper.GetResponseObject(response);
                    System.Console.WriteLine();
                }
                System.Console.Read();
                Main();
            }
            else
            {
                Console.WriteLine("You entered a string!!! Try again");
                Console.WriteLine();
                PostJson();
            }
        }