public WebhookService(IConfiguration configuration, AzureServiceBusService azureServiceBusService) { _configuration = configuration; _azureServiceBusService = azureServiceBusService; _queueName = _configuration["ServiceBusQueueName"]; _webhookEnpoint = _configuration["WebhookEndpoint"]; _restClient = new RestClient(_webhookEnpoint); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; }
public async Task <IHttpActionResult> PostOrder(Order order) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } order.CheckoutDateTime = DateTime.Now; order.Id = Guid.NewGuid().ToString(); order.OrderItems.ToList().ForEach(i => { i.Id = Guid.NewGuid().ToString(); }); db.Orders.Add(order); try { await db.SaveChangesAsync(); //TODO: Ioc & Interface & Repo var savedOrder = await GetOrderFromDB(order.Id); AzureServiceBusService serviceBus = new AzureServiceBusService(); await serviceBus.SendMessagesAsync($"User '{savedOrder.User.Name}' ordered '{savedOrder.OrderItems.Sum(i=>i.Quantity)}' items with total price {savedOrder.OrderItems.Sum(i => i.Quantity * i.Product.Price)} is placed in {savedOrder.CheckoutDateTime}, \r\nDiagnostic data: {Request.Headers.UserAgent} {this.Request.GetOwinContext()?.Request.RemoteIpAddress} {RequestContext.Principal.Identity?.Name}"); await serviceBus.Close(); await PushNotificationAsync(savedOrder); } catch (DbUpdateException ex) { if (OrderExists(order.Id)) { return(Conflict()); } else { throw; } } catch (Exception ex) { throw; } //return CreatedAtRoute("DefaultApi", new { id = order.Id }, order); return(Ok(order.Id)); }
// POST tables/Order //[Route("tables/Order/{userId}")] public async Task <IHttpActionResult> PostOrder(Order order) { order.CheckoutDateTime = DateTime.Now; order.Id = Guid.NewGuid().ToString(); order.OrderItems.ToList().ForEach(i => { i.Id = Guid.NewGuid().ToString(); }); //item.UserId = userId; Order current = await InsertAsync(order); serviceBus = new AzureServiceBusService(); await serviceBus.SendMessagesAsync($"New Order {current.Id} by {current.UserId} -- {current.CheckoutDateTime} -- {DateTime.Now.ToLongTimeString()}"); await serviceBus.Close(); //return CreatedAtRoute("Tables", new { id = current.Id }, current); return(Ok(new { id = current.Id })); }
public ValuesController(MemoryService memory, AzureServiceBusService serviceBus) { _memory = memory; _serviceBus = serviceBus; }
public WebhookService(AzureServiceBusService azureServiceBusService, IConfiguration configuration) { _azureServiceBusService = azureServiceBusService; _configuration = configuration; }
public void Setup() { _sut = new AzureServiceBusService(); }