public static AtgOrderReq CreateATGOrder(string orderId, string sellWhse, string shipPrice, string shipType, ShippingAddress shipTo, List <Item> items) { var order = new AtgOrderReq() { atgOrderId = orderId, shipFromWhse = sellWhse, sellWhse = sellWhse, notes = shipType, items = items, custAccountId = "POLLARDWTR", customerId = "54645", customerName = "Gene Parmesan", orderSubmitDate = "2020-07-30 08:16:58", sourceSystem = "B2S", orderRequiredDate = "2020-07-30", paymentOnAccount = new PaymentOnAccount() { payment = new Payment() { address1 = "4715 Frederick Dr. SW", cardType = "VI", city = "Atlanta", state = "GA", zip = "30336" } } }; order.shipping = new Shipping() { price = shipPrice, shipTo = new ShipTo() { address1 = shipTo.addressLine1, city = shipTo.city, state = shipTo.state, zip = shipTo.zip, country = "US", name = "Gene Parmesan", shipInstructionsPhoneNumberAreaDialing = "315", shipInstructionsPhoneNumberDialNumber = "7295356" } }; // Set static item fields for (var i = 0; i < order.items.Count; i++) { order.items[i].unitPriceCode = "EA"; order.items[i].description = "ci8318000259"; } return(order); }
public static IActionResult GetOrder( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "order/{id}")] HttpRequest req, [CosmosDB(ConnectionStringSetting = "AzureCosmosDBConnectionString")] DocumentClient cosmosClient, ILogger log, string id) { var collectionUri = UriFactory.CreateDocumentCollectionUri("sourcing-engine", ordersContainerName); var orderData = cosmosClient.CreateDocumentQuery <Document>(collectionUri, option) .Where(fo => fo.Id == id).AsEnumerable().FirstOrDefault(); if (orderData == null) { return(new NotFoundResult()); } AtgOrderReq order = (dynamic)orderData; return(new OkObjectResult(order)); }
public static AtgOrderRes SourceOrderFromSite(AtgOrderReq order) { var authCode = Environment.GetEnvironmentVariable("AZURE_SOURCE_ORDER_KEY"); var baseURL = "https://fergusonsourcingengine.azurewebsites.net/api/order/source?code="; var jsonRequest = JsonConvert.SerializeObject(order); var client = new RestClient(baseURL + authCode); var request = new RestRequest(Method.POST); request.AddHeader("Accept", "application/json"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json; charset=utf-8", jsonRequest, ParameterType.RequestBody); var jsonResponse = client.Execute(request).Content; var orderResponse = JsonConvert.DeserializeObject <AtgOrderRes>(jsonResponse); return(orderResponse); }
public static async Task SourceUnsourcedOrders( [TimerTrigger("0 */5 * * * *")] TimerInfo timer, // every 5 mins [CosmosDB(ConnectionStringSetting = "AzureCosmosDBConnectionString"), SwaggerIgnore] DocumentClient documentClient, ILogger log) { // Get orders within past 3 days in atg-orders container that are not in the orders container var query = new SqlQuerySpec { QueryText = "SELECT VALUE c FROM c WHERE c.lastModifiedDate > DateTimeAdd(\"dd\", -03, GetCurrentDateTime())" }; var ordersCollectionUri = UriFactory.CreateDocumentCollectionUri("sourcing-engine", "orders"); var atgOrdersCollectionUri = UriFactory.CreateDocumentCollectionUri("sourcing-engine", "atg-orders"); var atgOrderDocs = documentClient.CreateDocumentQuery <Document>(atgOrdersCollectionUri, query, option).AsEnumerable(); // Run sourcing engine on unsourced orders foreach (var atgOrderDoc in atgOrderDocs) { AtgOrderReq atgOrderReq = (dynamic)atgOrderDoc; query = new SqlQuerySpec { QueryText = "SELECT * FROM c WHERE c.id = @id", Parameters = new SqlParameterCollection() { new SqlParameter("@id", atgOrderReq.atgOrderId) } }; var orderDoc = documentClient.CreateDocumentQuery <Document>(ordersCollectionUri, query, option).AsEnumerable().FirstOrDefault(); var sourcingController = InitializeSourcingController(log); // If the order does not exist in orders container, run sourcing engine try { if (orderDoc == null) { log.LogInformation($"Order ID: {atgOrderReq.atgOrderId}"); log.LogInformation(@"Order: {Order}", atgOrderReq); var atgOrderRes = new AtgOrderRes(atgOrderReq); await sourcingController.StartSourcing(documentClient, atgOrderRes); } else // ensure that each line item has a shipFrom location { AtgOrderRes atgOrderRes = (dynamic)orderDoc; var requiresSourcing = OrderController.ValidateItemShipFroms(atgOrderRes.items); if (requiresSourcing) { await sourcingController.StartSourcing(documentClient, atgOrderRes); } } } catch (Exception ex) { log.LogWarning(@"Missing required field: {E}", ex); var title = "Error in SourceUnsourcedOrders: "; var text = $"Error message: {ex.Message}. Stacktrace: {ex.StackTrace}"; var teamsMessage = new TeamsMessage(title, text, "red", errorLogsUrl); teamsMessage.LogToTeams(teamsMessage); log.LogError(title + @"{E}", ex); } } }