public Order GetOrder(int orderId)
        {
            var order = new Order();

            // Retrieve the order record.
            if (_db.Orders.Any(o => o.OrderId == orderId))
            {
                order = _db.Orders.Include(od => od.OrderDetails.Select(p => p.Product)).Single(o => o.OrderId == orderId);
            }
           
            // Success.
            return order;
        }
        public ActionResult Details(int Id)
        {
            var order = new Order();
            using (var orderActions = new OrderActions())
            {
                order = orderActions.GetOrder(Id);
            }

            var vm = new ViewModels.DetailsViewModel
            {
                DisplayName = base.DisplayName,
                Order = order
            };

            return View(vm);
        }
示例#3
0
        private async Task RunAsync(CancellationToken cancellationToken)
        {
            // Generate a new PDF-based receipt, save it to Azure Blob storage, and update
            // the customer's order record with the path to the PDF.
            while (!cancellationToken.IsCancellationRequested)
            {
                Trace.TraceInformation("Checking Order Status");

                // Grab order id from the Azure Queue.
                var azureStorageMethods = new AzureStorageMethods();
                int orderId = await azureStorageMethods.GetOrderIdFromQueue();

                if (orderId > 0)
                {
                    // We have received a new Order Id in the queue, requesting a generated Pdf receipt.
                    var order = new Order();
                    using (var orderActions = new OrderActions())
                    {
                        order = orderActions.GetOrder(orderId);

                        if (order != null && order.OrderId > 0)
                        {
                            var orderVm = DataMethods.MapOrderToViewModel(order);

                            var fileName = string.Format("ContosoSportsLeague-Store-Receipt-{0}.pdf", order.OrderId);
                            var receipt = new GenerateReceiptPDF().CreatePdfReport(orderVm, fileName);
                            Trace.TraceInformation("PDF generated. Saving to blob storage...");
                            var receiptUri = azureStorageMethods.UploadPdfToBlob(receipt, fileName);

                            // Update the generated receipt Uri on the order:
                            orderActions.UpdateReceiptUri(order.OrderId, receiptUri);
                        }
                        else
                        {
                            // We couldn't find the order for the passed in Order Id. We should log this somewhere.
                            Trace.TraceError("Could not find the order record based off of the passed in Id: " + orderId.ToString() + ". Receipt PDF not generated.");
                        }
                    }
                }
                Trace.TraceInformation("Pausing for 5 seconds before next check.");
                System.Threading.Thread.Sleep(5000);
            }
        }
示例#4
0
 public static OrderViewModel MapOrderToViewModel(Order order)
 {
     var orderVm = new OrderViewModel
     {
         OrderId = order.OrderId,
         OrderDate = order.OrderDate,
         Total = order.Total,
         FirstName = order.FirstName,
         LastName = order.LastName,
         Email = order.Email,
         Address = order.Address,
         City = order.City,
         State = order.State,
         PostalCode = order.PostalCode,
         Country = order.Country,
         Phone = order.Phone
     };
     orderVm.OrderDetails = DataMethods.MapOrderDetailToViewModel(order.OrderDetails);
     return orderVm;
 }