public IActionResult Index() { var fileSystemLog = new FileSystemLogSpecification("LOG"); var repository = new LoggerRepository(); // TODO: bool log = repository.LogInfo(fileSystemLog); return(Ok()); }
public bool ConfirmOrdersShipment() { // init the Amazon order API var config = new MarketplaceWebServiceConfig { ServiceURL = "https://mws.amazonservices.com" }; config.SetUserAgentHeader(_ApplicationName, _Version, "C#"); var serviceClient = new MarketplaceWebServiceClient(_credential.AccessKeyId, _credential.SecretKey, config); var orderFulfillmentList = new List <OrderFulfillment>(); // get the unshipped orders with tracking number for confirming its shipment var unshippedOrderFeeds = _orderRepository.GetUnshippedOrdersForShipment(ChannelName); if (!unshippedOrderFeeds.Any()) { Console.WriteLine("No unshipped orders found from {0} for shipment confirmation.", ChannelName); return(true); } try { Console.WriteLine("Sending {0} orders for shipment confirmation...", unshippedOrderFeeds.Count); // create the order fulfillment unshippedOrderFeeds.ForEach(order => { // create fulfillment item list from the order items var fulfillmentItems = new List <OrderFulfillmentItem>(); foreach (var item in order.OrderItems) { fulfillmentItems.Add(new OrderFulfillmentItem { Item = item.OrderItemId, Quantity = item.Quantity.ToString() }); } // then, the order fulfillment information orderFulfillmentList.Add(new OrderFulfillment { Item = order.OrderId, FulfillmentDate = order.FulfillmentDate, FulfillmentData = new OrderFulfillmentFulfillmentData { Item = order.Carrier.Code, ShippingMethod = "Ground", // order.ShippingMethod, ShipperTrackingNumber = order.ShipperTrackingNumber }, Item1 = fulfillmentItems.ToArray() }); }); // iterate to the order fulfillment and add it into envelope message var envelopeMessages = new List <AmazonEnvelopeMessage>(); for (var i = 0; i < orderFulfillmentList.Count; i++) { var message = new AmazonEnvelopeMessage { MessageID = string.Format("{0}", i + 1), Item = orderFulfillmentList[i] }; envelopeMessages.Add(message); } // create Amazon envelope object var amazonEnvelope = new AmazonEnvelope { Header = new Header { DocumentVersion = "1.01", MerchantIdentifier = _credential.MerchantId }, MessageType = AmazonEnvelopeMessageType.OrderFulfillment, Message = envelopeMessages.ToArray() }; // let's add these orders to the shipment history addOrderShipmentHistoryAsync(unshippedOrderFeeds); // parse the envelope into file var xmlFullName = XmlParser.WriteXmlToFile(amazonEnvelope, "AmazonOrderFulfillment"); // create feed controller and send the confirmation shipment feed var submitController = new SubmitFeedController(serviceClient, _logger, _credential.MarketplaceId, _credential.MerchantId, _ApplicationName); var streamResponse = submitController.SubmitFeedAndGetResponse(xmlFullName, AmazonFeedType._POST_ORDER_FULFILLMENT_DATA_); parsedResultStreamAndLogReport(streamResponse, AmazonEnvelopeMessageType.OrderFulfillment, _ApplicationName); _logger.LogInfo(LogEntryType.AmazonOrdersProvider, string.Format("{1}:{2} - Successfully sent confirming order shipment for Order IDs: \"{0}\"", string.Join("\", \"", unshippedOrderFeeds.Select(x => x.OrderId)), ChannelName, _ApplicationName, Constants.APP_NAME)); Console.WriteLine("Successfully sent confirming order shipment for Order IDs: \"{0}\"", string.Join("\", \"", unshippedOrderFeeds.Select(x => x.OrderId))); return(true); } catch (Exception ex) { _logger.LogError(LogEntryType.AmazonOrdersProvider, string.Format("{0}:{4} Error in confirming order shipment for for Order IDs: \"{3}\". <br/>Error Message: {1} <br/> Access Key: {2}", ChannelName, (ex.InnerException != null ? string.Format("{0} <br/>Inner Message: {1}", ex.Message, ex.InnerException.Message) : ex.Message), _credential.AccessKeyId, string.Join("\", \"", unshippedOrderFeeds.Select(x => x.OrderId)), _ApplicationName), ex.StackTrace); Console.WriteLine("Error in sending shipment confirmation! Error Message: {0} \nStackTrace: {1} ", ex.Message, ex.StackTrace); // let's delete the order confirmation deleteOrderShipmentHistoryAsync(unshippedOrderFeeds); return(false); } }
public bool ConfirmOrdersShipment() { // get the unshipped orders with tracking number for confirming its shipment var unshippedOrderFeeds = _orderRepository.GetUnshippedOrdersForShipment(ChannelName); var bigCommerceOrdersList = new List <BigCommerce4Net.Domain.Order>(); var successConfirms = 0; if (!unshippedOrderFeeds.Any()) { Console.WriteLine("No unshipped orders found from {0} for shipment confirmation.", ChannelName); return(true); } try { Console.WriteLine("Sending {0} orders for shipment confirmation...", unshippedOrderFeeds.Count); foreach (var marketplaceOrder in unshippedOrderFeeds) { if (!marketplaceOrder.OrderItems.Any()) { return(false); } var orderid = Convert.ToInt32(marketplaceOrder.OrderId); var bcOrderResponse = _client.Orders.Get(orderid); var bcOrder = bcOrderResponse.Data; var updatedata = new { status_id = OrderStatusEnum.Shipped }; // Create BC Order Shipment var shipmentItems = new List <OrdersShipmentItem>(); foreach (var orderitems in marketplaceOrder.OrderItems) { var orderItemId = Convert.ToInt32(orderitems.OrderItemId); shipmentItems.Add(new OrdersShipmentItem { OrderProductId = orderItemId, Quantity = orderitems.Quantity }); } var orderAddressID = 0; var shippingAddresses = GetShippingAddresses(bcOrder.Id); if (shippingAddresses.Count > 0) { orderAddressID = shippingAddresses.First().Id; } var shipmentdata = new { order_address_id = orderAddressID, items = shipmentItems, tracking_number = marketplaceOrder.ShipperTrackingNumber, shipping_method = marketplaceOrder.ShippingMethod, shipping_provider = marketplaceOrder.CarrierCode != null ? marketplaceOrder.CarrierCode : "", }; // API Create Shipment based on Order var responseShipment = _client.OrdersShipments.Create(orderid, shipmentdata); if (responseShipment.RestResponse.StatusCode == System.Net.HttpStatusCode.Created) { // API Update on the Order var responseOrder = _client.Orders.Update(orderid, updatedata); if (responseOrder.RestResponse.StatusCode == System.Net.HttpStatusCode.OK) { successConfirms++; var tempList = new List <MarketplaceOrderFulfillment>(); tempList.Add(marketplaceOrder); // let's add these orders to the shipment history addOrderShipmentHistoryAsync(tempList); } } } _logger.LogInfo(LogEntryType.BigCommerceOrders, string.Format("Successfully sent confirming order shipment for {0} order items: <br/>Shipment confirmation was done by {1}", successConfirms, Constants.APP_NAME)); Console.WriteLine("Successfully sent confirming order shipment for {0} order items: ", successConfirms); return(true); } catch (Exception ex) { _logger.LogError(LogEntryType.BigCommerceOrders, string.Format("{4} Error in confirming order shipment for {0} - Number of Orders: {3}. <br/>Error Message: {1} <br/> Access Key: {2}", ChannelName, (ex.InnerException != null ? string.Format("{0} <br/>Inner Message: {1}", ex.Message, ex.InnerException.Message) : ex.Message), _credential.Username, bigCommerceOrdersList.Count, _ApplicationName), ex.StackTrace); Console.WriteLine("Error in sending shipment confirmation! Error Message: {0} \nStackTrace: {1} ", ex.Message, ex.StackTrace); // let's delete the order confirmation deleteOrderShipmentHistoryAsync(unshippedOrderFeeds); return(false); } }