public AcumaticaCustomer CreateAcumaticaCustomerRecord(ShopifyCustomer shopifyRecord, Customer acumaticaCustomer)
        {
            using (var transaction = _acumaticaOrderRepository.BeginTransaction())
            {
                var newRecord = new AcumaticaCustomer();

                newRecord.AcumaticaCustomerId       = acumaticaCustomer.CustomerID.value;
                newRecord.AcumaticaMainContactEmail = acumaticaCustomer.MainContact.Email.value;
                newRecord.DateCreated = DateTime.UtcNow;
                newRecord.LastUpdated = DateTime.UtcNow;

                shopifyRecord.AcumaticaCustomer = newRecord;
                shopifyRecord.NeedsCustomerPut  = false;

                _acumaticaOrderRepository.InsertCustomer(newRecord);

                _acumaticaJsonService.Upsert(
                    AcumaticaJsonType.Customer,
                    acumaticaCustomer.CustomerID.value,
                    acumaticaCustomer.SerializeToJson());

                transaction.Commit();
                return(newRecord);
            }
        }
Esempio n. 2
0
        private AcumaticaSalesOrder FindAndUpsertSalesOrderData(SalesOrder order)
        {
            using (var transaction = _orderRepository.BeginTransaction())
            {
                var orderNbr       = order.OrderNbr.value;
                var shopifyOrderId = order.CustomerOrder.value.ToLongAlt(-1);
                var orderRecord    = _orderRepository.RetrieveSalesOrder(orderNbr);

                bool unknownRef = false;

                if (orderRecord == null)
                {
                    // Skip Sales Orders that were not intentionally loaded into Acumatica
                    //
                    orderRecord = _orderRepository.FindSalesOrderByShopifyId(shopifyOrderId);

                    if (orderRecord == null)
                    {
                        return(null);
                    }

                    unknownRef = true;
                }

                if (unknownRef)
                {
                    _executionLogService.Log(
                        LogBuilder.FillingUnknownAcumaticaSalesOrderRef(orderRecord.ShopifyOrder, orderRecord));
                }

                _executionLogService.Log(LogBuilder.DetectedUpdateAcumaticaOrder(orderRecord));

                _acumaticaJsonService.Upsert(
                    AcumaticaJsonType.SalesOrderShipments,
                    orderNbr,
                    SalesOrderType.SO,
                    order.SerializeToJson());

                // Again, to be tested
                //
                // orderRecord.AcumaticaQtyTotal = (int)order.Details.Sum(x => x.OrderQty.value);

                orderRecord.Ingest(order);
                orderRecord.LastUpdated = DateTime.UtcNow;

                _orderRepository.SaveChanges();
                transaction.Commit();

                return(orderRecord);
            }
        }
        private void UpdateCustomerToPersist(Customer acumaticaCustomer)
        {
            var existingRecord = _orderRepository.RetrieveCustomer(acumaticaCustomer.CustomerID.value);

            if (existingRecord != null)
            {
                using (var transaction = _orderRepository.BeginTransaction())
                {
                    _acumaticaJsonService.Upsert(
                        AcumaticaJsonType.Customer,
                        acumaticaCustomer.CustomerID.value,
                        acumaticaCustomer.SerializeToJson());
                    existingRecord.AcumaticaMainContactEmail = acumaticaCustomer.MainContact.Email.value;
                    existingRecord.LastUpdated = DateTime.UtcNow;
                    _orderRepository.SaveChanges();
                    transaction.Commit();
                }
            }
        }