Exemple #1
0
        public AmazonOrder ScheduleSync(Order order)
        {
            switch (order.OrderStatus)
            {
            case OrderStatusEnum.Unshipped:
            case OrderStatusEnum.PartiallyShipped:
            case OrderStatusEnum.Shipped:
            case OrderStatusEnum.Canceled:
            {
                if (!_importAmazonOrderService.IsCurrencyValid(order))
                {
                    _amazonLogService.Add(AmazonLogType.Orders, AmazonLogStatus.Stage, null, null,
                                          AmazonApiSection.Orders,
                                          null, null, null, null,
                                          string.Format(
                                              "Amazon Order #{0} uses different currency than current MrCMS Site.",
                                              order.AmazonOrderId));
                }
                else
                {
                    var amazonOrder     = _amazonOrderService.GetByAmazonOrderId(order.AmazonOrderId);
                    var amazonOrderData = _amazonOrderSyncInfoService.GetByAmazonOrderId(order.AmazonOrderId).ToList();

                    if (order.OrderStatus == OrderStatusEnum.Canceled)
                    {
                        return(amazonOrder);
                    }

                    var newAmazonOrderData = new AmazonOrderSyncData
                    {
                        OrderId   = order.AmazonOrderId,
                        Operation = (amazonOrder == null
                                            ? (amazonOrderData.Any(x => x.Operation == SyncAmazonOrderOperation.Add) ? SyncAmazonOrderOperation.Update : SyncAmazonOrderOperation.Add) : SyncAmazonOrderOperation.Update),
                        Status = SyncAmazonOrderStatus.Pending,
                        Data   = AmazonAppHelper.SerializeToJson(order),
                        Site   = CurrentRequestData.CurrentSite
                    };

                    if (amazonOrder != null)
                    {
                        newAmazonOrderData.AmazonOrder = amazonOrder;
                    }

                    _amazonOrderSyncInfoService.Add(newAmazonOrderData);

                    return(amazonOrder);
                }
            }
            break;
            }
            return(null);
        }
Exemple #2
0
        public AmazonOrder UpdateOrder(AmazonOrderSyncData amazonOrderSyncData)
        {
            var existingAmazonOrder = _amazonOrderService.GetByAmazonOrderId(amazonOrderSyncData.OrderId);

            if (amazonOrderSyncData.Operation == SyncAmazonOrderOperation.Add && existingAmazonOrder != null)
            {
                amazonOrderSyncData.Status      = SyncAmazonOrderStatus.Synced;
                amazonOrderSyncData.AmazonOrder = existingAmazonOrder;
                _amazonOrderSyncDataService.Update(amazonOrderSyncData);
                _amazonOrderSyncDataService.Delete(amazonOrderSyncData);
                return(existingAmazonOrder);
            }

            if (amazonOrderSyncData.AmazonOrder == null && existingAmazonOrder != null)
            {
                amazonOrderSyncData.AmazonOrder = existingAmazonOrder;
                _amazonOrderSyncDataService.Update(amazonOrderSyncData);
            }

            var amazonOrder = amazonOrderSyncData.AmazonOrder = amazonOrderSyncData.AmazonOrder ?? new AmazonOrder();
            var order       = AmazonAppHelper.DeserializeFromJson <Order>(amazonOrderSyncData.Data);

            var success = ProcessOrder(order, ref amazonOrder, amazonOrderSyncData.Operation == SyncAmazonOrderOperation.Add);

            if (success)
            {
                amazonOrderSyncData.Status      = SyncAmazonOrderStatus.Synced;
                amazonOrderSyncData.AmazonOrder = amazonOrder;
                _amazonOrderSyncDataService.Update(amazonOrderSyncData);
                _amazonOrderSyncDataService.Delete(amazonOrderSyncData);
            }
            else
            {
                amazonOrderSyncData.Status      = SyncAmazonOrderStatus.Pending;
                amazonOrderSyncData.AmazonOrder = amazonOrder;
                _amazonOrderSyncDataService.Update(amazonOrderSyncData);
            }

            return(amazonOrder);
        }