Example #1
0
 private void Update(AmazonOrderSyncData data)
 {
     if (data.Status != SyncAmazonOrderStatus.Pending)
         return;
     LogStatus(data, SyncAmazonOrderStatus.InProgress);
     _updateAmazonOrder.UpdateOrder(data);
 }
 public AmazonOrderSyncData Update(AmazonOrderSyncData item)
 {
     _session.Transact(session =>
     {
         if (item.AmazonOrder != null)
         {
             item.AmazonOrder = session.Get<AmazonOrder>(item.AmazonOrder.Id);
             item.Site = session.Get<Site>(item.AmazonOrder.Site.Id);
         }
         session.Update(item);
     });
     _amazonLogService.Add(AmazonLogType.OrdersSyncData, AmazonLogStatus.Update,
                         null, null, null, null, null, null, null, "Amazon Order #" + item.OrderId);
     return item;
 }
        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;
        }
Example #4
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;

        }
        public AmazonOrderSyncData Add(AmazonOrderSyncData item)
        {
            _session.Transact(session =>
            {
                if (item.AmazonOrder != null)
                {
                    item.AmazonOrder = session.Get<AmazonOrder>(item.AmazonOrder.Id);
                    item.Site = session.Get<Site>(item.AmazonOrder.Site.Id);
                }
                //sanity check there are no orders already in the table as we were getting duplicates
                var itemInTable =
                    session.QueryOver<AmazonOrderSyncData>()
                           .Where(x => x.OrderId == item.OrderId && x.Operation == SyncAmazonOrderOperation.Add)
                           .RowCount();

                if (itemInTable == 0)
                    session.Save(item);
            });
            _amazonLogService.Add(AmazonLogType.OrdersSyncData, AmazonLogStatus.Insert,
                                null, null, null, null, null, null, null, "Amazon Order #" + item.OrderId);
            return item;
        }
Example #6
0
 private void LogStatus(AmazonOrderSyncData data, SyncAmazonOrderStatus status)
 {
     data.Status = status;
     _amazonOrderSyncDataService.Update(data);
 }
 public void Delete(AmazonOrderSyncData item)
 {
     _amazonLogService.Add(AmazonLogType.OrdersSyncData, AmazonLogStatus.Delete,
                        null, null, null, null, null, null, null, "Amazon Order #" + item.OrderId);
     _session.Transact(session => session.Delete(item));
 }