コード例 #1
0
        public async Task<ActionResult> DisplayProducts()
        {
            List<Product> lstProducts = null;
            ProductOrder productOrder = new ProductOrder();
            List<AddProduct> lstAddProducts = new List<AddProduct>();

            string value = cache.StringGet("Products");
            if (null != value)
            {
                lstProducts = JsonConvert.DeserializeObject<List<Product>>(value);
            }
            else
            {
                lstProducts = await azureDocDBHelper.GetProducts();
                value = JsonConvert.SerializeObject(lstProducts);
                cache.StringSet("Products", value);
            }
            foreach (Product pd in lstProducts)
            {
                AddProduct addPd = new AddProduct();
                addPd.ProductId = pd.ProductId;
                addPd.ProductName = pd.ProductName;
                addPd.UnitPrice = pd.UnitPrice;
                lstAddProducts.Add(addPd);
            }
            productOrder.lstProducts = lstAddProducts;
            return View(productOrder);
        }
コード例 #2
0
        public ActionResult SubmitOrder(ProductOrder productOrder)
        {

            //if (ModelState.IsValid)
            {
                try
                {
                    ViewBag.SubmitResponse = string.Empty;
                    AzureGuidance.Domain.Order order = new AzureGuidance.Domain.Order();
                    order.CustomerName = productOrder.order.CustomerName;
                    order.OrderDate = DateTime.Now;
                    order.EmailId = productOrder.order.EmailId;
                    order.ProductOrderDetailsList = new List<ProductDetails>();
                    foreach (AddProduct p in productOrder.lstProducts)
                    {
                        if (true == p.SelectProduct)
                        {
                            ProductDetails productDetails = new ProductDetails();
                            productDetails.ProductName = p.ProductName;
                            productDetails.ProductQuantity = p.ProductQuantity;
                            order.TotalDue += p.UnitPrice * p.ProductQuantity;
                            order.orderStatus = "Processed";
                            order.OrderId  = Guid.NewGuid();
                            order.ProductOrderDetailsList.Add(productDetails);
                            p.ProductQuantity = 0;
                            p.SelectProduct = false;
                        }

                    }
                    var message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(order);
                    if (null == ServiceBusTopicHelper.OrdersTopicClient)
                    {
                        ServiceBusTopicHelper.Initialize();
                    }
                    ServiceBusTopicHelper.OrdersTopicClient.Send(message);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            ProductOrder pOrder = new ProductOrder();
            List<AddProduct> lstProducts = new List<AddProduct>();

            pOrder.lstProducts = productOrder.lstProducts;
            ModelState.Clear();
            ViewBag.SubmitResponse = "Order proccessed successfully.";
            return View("DisplayProducts", pOrder);
        }
コード例 #3
0
 public async Task<ActionResult> DisplayProducts()
 {
     List<Product> lstProducts;
     ProductOrder productOrder = new ProductOrder();
     List<AddProduct> lstAddProducts = new List<AddProduct>();
     lstProducts = await azureDocDBHelper.GetProducts();
     foreach (Product pd in lstProducts)
     {
         AddProduct addPd = new AddProduct();
         addPd.ProductId = pd.ProductId;
         addPd.ProductName = pd.ProductName;
         addPd.UnitPrice = pd.UnitPrice;
         lstAddProducts.Add(addPd);
     }
     productOrder.lstProducts = lstAddProducts;
     return View(productOrder);
 }