public void SendPurchase(PurchaseEvent purchase) { var serializedString = JsonConvert.SerializeObject(purchase); var 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); }
public ActionResult Buy(int id) { var customer = _customerRepository.GetCustomerByName(User.Identity.Name); var product = _productsRepository.GetProduct(id); var promotion = _promotionsRepository.GetPromotion(customer.CustomerId, product.Id); var purchaseEvent = new PurchaseEvent { CustomerId = customer.CustomerId, ProductId = id, Price = promotion != null ? promotion.NewPrice : product.Price, PurchaseTime = DateTime.Now, OrderId = Guid.NewGuid() }; _telemetryRepository.SendPurchase(purchaseEvent); Thread.Sleep(TimeSpan.FromSeconds(5)); return new HttpStatusCodeResult(HttpStatusCode.OK); }