Пример #1
0
        public IActionResult Index()
        {
            {
                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri("http://localhost:58639");
                client.DefaultRequestHeaders.Accept.Add(
                    new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));

                OrderedProducts sales = new OrderedProducts()
                {
                    CustomerId = 1,
                    OrderDate  = DateTime.Now,
                    Products   = DemoProductContainer.GetProducts()
                };

                string              json     = JsonConvert.SerializeObject(sales);
                HttpContent         content  = new StringContent(json, Encoding.UTF8, "application/json");
                HttpResponseMessage response = client.PostAsync("api/order", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    string[] data = (string[])response.Content.ReadAsAsync(typeof(string[])).Result;
                    //    return Invoice(sales, data);
                    CustomerDetails details  = new CustomerDetails();
                    Customer        customer = details.GetCustomerById(sales.CustomerId);
                    ViewBag.customer     = customer.CustomerMailId;
                    ViewBag.OrderInvoice = data;
                    ViewBag.customer     = customer;
                    ViewBag.orderdate    = sales.OrderDate;
                    return(View("Invoice", sales));
                }

                ViewBag.error = response.ReasonPhrase;
                return(View("Error"));
            }
        }
Пример #2
0
        public IActionResult Invoice(OrderedProducts products, string[] data)
        {
            CustomerDetails details  = new CustomerDetails();
            Customer        customer = details.GetCustomerById(products.CustomerId);

            ViewBag.OrderInvoice = data;
            ViewBag.customer     = customer;
            return(View("Invoice", products));
        }