Example #1
0
        private void AddActions(IUnitOfWork db, ParentItemDTO parentItemDto)
        {
            foreach (var item in parentItemDto.Variations)
            {
                var actions = new List <SystemActionType>()
                {
                    SystemActionType.UpdateOnMarketProductRelationship,
                    SystemActionType.UpdateOnMarketProductImage,
                };

                foreach (var actionType in actions)
                {
                    var newAction = new SystemActionDTO()
                    {
                        ParentId  = null,
                        Status    = (int)SystemActionStatus.None,
                        Type      = (int)actionType,
                        Tag       = item.Id.ToString(),
                        InputData = null,

                        CreateDate = _time.GetUtcTime(),
                        CreatedBy  = null,
                    };
                    db.SystemActions.AddAction(newAction);
                }
            }
            db.Commit();
        }
        public long AddAction(IUnitOfWork db,
                              SystemActionType type,
                              string tag,
                              ISystemActionInput inputData,
                              long?parentActionId,
                              long?by,
                              SystemActionStatus?status = SystemActionStatus.None)
        {
            var input = JsonConvert.SerializeObject(inputData);

            _logService.Info("AddAction, type=" + type + ", inputData=" + input);
            var newAction = new SystemActionDTO()
            {
                ParentId  = parentActionId,
                Status    = (int)status,
                Type      = (int)type,
                Tag       = tag,
                InputData = input,

                CreateDate = _time.GetUtcTime(),
                CreatedBy  = by,
            };

            db.SystemActions.AddAction(newAction);

            return(newAction.Id);
        }
        public RefundViewModel(SystemActionDTO action)
        {
            Id = action.Id;

            var input = JsonConvert.DeserializeObject <ReturnOrderInput>(action.InputData);

            if (action.OutputData != null)
            {
                var output = JsonConvert.DeserializeObject <ReturnOrderOutput>(action.OutputData);
                Message = output.ResultMessage;
            }

            Amount      = RefundHelper.GetAmount(input);
            RefundMoney = input.RefundMoney;
            Status      = action.Status;
            Date        = action.CreateDate;
            By          = action.CreatedBy;
        }
        public void AddAction(SystemActionDTO action)
        {
            var dbAction = new SystemAction()
            {
                ParentId = action.ParentId,

                Type      = action.Type,
                Tag       = action.Tag,
                InputData = action.InputData,
                Status    = action.Status,

                CreateDate = action.CreateDate,
                CreatedBy  = action.CreatedBy,
            };

            unitOfWork.GetSet <SystemAction>().Add(dbAction);
            unitOfWork.Commit();

            action.Id = dbAction.Id;
        }
Example #5
0
        public UploadOrderFeedViewModel(SystemActionDTO action)
        {
            Id     = action.Id;
            Status = action.Status;
            var inputModel  = SystemActionHelper.FromStr <PublishFeedInput>(action.InputData);
            var outputModel = SystemActionHelper.FromStr <PublishFeedOutput>(action.OutputData);

            FileName        = inputModel.FileName;
            FieldMappingsId = inputModel.FieldMappingsId;

            ProgressPercent = outputModel?.ProgressPercent ?? 0;

            CreateDate = action.CreateDate;

            ParsedCount              = outputModel?.ParsedCount;
            MatchedCount             = outputModel?.MatchedCount;
            Valid1OperationCount     = outputModel?.Valid1OperationCount;
            Valid2OperationCount     = outputModel?.Valid2OperationCount;
            Processed1OperationCount = outputModel?.Processed1OperationCount;
            Processed2OperationCount = outputModel?.Processed2OperationCount;
        }
        public void Update(IUnitOfWork db,
                           ILogService log,
                           ISystemActionService actionService,
                           IPriceManager priceManager,
                           MarketType market,
                           string marketplaceId,
                           DateTime when,
                           long?by)
        {
            var parentItem = db.ParentItems.Get(Id);

            if (parentItem != null)
            {
                var childItems = db.Items.GetListingsByParentASIN(market, marketplaceId, parentItem.ASIN);

                if (ChangePriceOffset.HasValue)
                {
                    foreach (var childItem in childItems)
                    {
                        log.Info("Child price was changed, from=" + childItem.CurrentPrice + ", to=" +
                                 (childItem.CurrentPrice + ChangePriceOffset.Value));

                        var oldPrice = childItem.CurrentPrice;
                        childItem.CurrentPrice        += ChangePriceOffset.Value;
                        childItem.CurrentPriceInUSD    = PriceHelper.RougeConvertToUSD(childItem.CurrentPriceCurrency, childItem.CurrentPrice);
                        childItem.PriceUpdateRequested = true;

                        priceManager.LogListingPrice(db,
                                                     PriceChangeSourceType.ParentItemOffset,
                                                     childItem.Id,
                                                     childItem.SKU,
                                                     childItem.CurrentPrice,
                                                     oldPrice,
                                                     when,
                                                     by);
                    }
                    db.Commit();
                }

                parentItem.SKU              = SKU;
                parentItem.OnHold           = OnHold;
                parentItem.LockMarketUpdate = LockMarketUpdate;

                if (parentItem.ManualImage != ManualImage)
                {
                    log.Info("Image changed: " + parentItem.ManualImage + " => " + ManualImage);
                    parentItem.ManualImage = ManualImage;

                    if (!MarketHelper.IsAmazon((MarketType)parentItem.Market))
                    {
                        foreach (var child in childItems)
                        {
                            var newAction = new SystemActionDTO()
                            {
                                ParentId  = null,
                                Status    = (int)SystemActionStatus.None,
                                Type      = (int)SystemActionType.UpdateOnMarketProductImage,
                                Tag       = child.Id.ToString(),
                                InputData = null,

                                CreateDate = when,
                                CreatedBy  = null,
                            };
                            db.SystemActions.AddAction(newAction);
                        }
                    }
                }

                parentItem.UpdateDate = when;
                parentItem.UpdatedBy  = by;

                db.Commit();

                var lastComment = db.ProductComments.UpdateComments(
                    Comments.Select(c => new CommentDTO()
                {
                    Id      = c.Id,
                    Message = c.Comment
                }).ToList(),
                    Id,
                    when,
                    by);

                Comment = lastComment != null ? lastComment.Message : "";
            }
        }