public void SendPurchase(PurchaseEvent purchase)
        {
            var serializedString = JsonConvert.SerializeObject(purchase);
            EventData data = new EventData(Encoding.UTF8.GetBytes(serializedString))
            {
                PartitionKey = purchase.productId.ToString()
            };

            // Set user properties if needed
            data.Properties.Add("Type", "Telemetry_" + DateTime.UtcNow.ToLongTimeString());

            _eventHubs._purchaseClient.Send(data);

            //TODO: Add output to log here.
        }
        public ActionResult Buy(Int64 id)
        {
            var customer = _customerRepository.GetCustomerByName(User.Identity.Name);
            var product = _productsRepository.GetProduct(id);
            var promotion = _promotionsRepository.GetPromotion(customer.Id, product.Id);

            var purchaseEvent = new PurchaseEvent
            {
                customerId = customer.Id,
                productId = id,
                price = promotion != null ? promotion.NewPrice : product.Price,
                purchaseTime = DateTime.Now,
                orderId = Guid.NewGuid()
            };

            _telemetryRepository.SendPurchase(purchaseEvent);

            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

            return new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
        }