コード例 #1
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);
        }
コード例 #2
0
        public  async Task<List<ProductDetails>> GetOrderProductsDetails(Guid orderID)
        {
            List<ProductDetails> listProductDetails = new List<ProductDetails>();
            if (null == client)
            {
                await InitializeDocumentDB();
            }

            string sQuery = string.Format(@"select c.ProductOrderDetailsList from  orderdetails as c  where c.OrderId = ""{0}""", orderID);
            //9858af52-70d8-465c-8b14-046b8148c98b
            var queryResult = client.CreateDocumentQuery(collection.SelfLink, sQuery);
            //var family = query.AsEnumerable().FirstOrDefault();
            var str = queryResult.AsEnumerable().FirstOrDefault();
            foreach (var pd in str.ProductOrderDetailsList)
            {
                ProductDetails prodDetails = new ProductDetails();
                prodDetails.ProductName = pd.ProductName;
                prodDetails.ProductQuantity = pd.ProductQuantity;
                listProductDetails.Add(prodDetails);
            }
            return listProductDetails;
       }
コード例 #3
0
  public  async Task<List<ProductDetails>> GetOrderProductsDetails(Guid orderID)
  {
      List<ProductDetails> listProductDetails = new List<ProductDetails>();
      if (null == client)
      {
          await InitializeDocumentDB();
      }
      collection = client.CreateDocumentCollectionQuery(database.SelfLink).Where(c => c.Id == "OrderDetails").ToArray().FirstOrDefault(); 
      //string query = string.Format(@"select c.ProductOrderDetailsList from  orderdetails as c  where c.OrderId = ""{0}""", orderID);
      var queryResult = from c in client.CreateDocumentQuery<Order>(collection.SelfLink) where c.OrderId == orderID select c.ProductOrderDetailsList;
      
      //var queryResult = client.CreateDocumentQuery(collection.SelfLink, query);
      var str = queryResult.AsEnumerable().FirstOrDefault();
      foreach (var pd in str)
      {
          ProductDetails prodDetails = new ProductDetails();
          prodDetails.ProductName = pd.ProductName;
          prodDetails.ProductQuantity = pd.ProductQuantity;
          listProductDetails.Add(prodDetails);
      }
      return listProductDetails;
 }