Пример #1
0
 public StyleManager(ILogService log,
                     ITime time,
                     IStyleHistoryService styleHistoryService)
 {
     _log  = log;
     _time = time;
     _styleHistoryService = styleHistoryService;
 }
 public UploadOrderFeedService(IDbFactory dbFactory,
                               ITime time,
                               ILogService log,
                               IAutoCreateListingService listingCreateService,
                               ISystemActionService systemAction,
                               IStyleHistoryService styleHistory)
 {
     _log                  = log;
     _time                 = time;
     _dbFactory            = dbFactory;
     _listingCreateService = listingCreateService;
     _systemAction         = systemAction;
     _styleHistory         = styleHistory;
 }
Пример #3
0
        public AmazonReportService(AmazonReportType reportType,
                                   long companyId,
                                   AmazonApi api,
                                   ILogService log,
                                   ITime time,
                                   IDbFactory dbFactory,
                                   ISyncInformer syncInfo,
                                   IStyleManager styleManager,
                                   INotificationService notificationService,
                                   IStyleHistoryService styleHistoryService,
                                   IItemHistoryService itemHistoryService,
                                   ISystemActionService actionService,
                                   IReportParser parser,
                                   string path = "")
        {
            _log       = log;
            _time      = time;
            _dbFactory = dbFactory;

            _api = api;

            _reportInfo = new AmazonReportInfo();
            _reportInfo.ReportRequestId = String.Empty;

            _path          = path;
            _companyId     = companyId;
            _syncInfo      = syncInfo;
            _reportType    = reportType;
            _parser        = parser;
            _actionService = actionService;

            var parseContext = new ParseContext()
            {
                Log                 = log,
                Time                = time,
                DbFactory           = dbFactory,
                ActionService       = actionService,
                StyleManager        = styleManager,
                NotificationService = notificationService,
                StyleHistoryService = styleHistoryService,
                ItemHistoryService  = itemHistoryService,
                SyncInformer        = syncInfo,
                CompanyId           = companyId
            };

            _parser.Init(parseContext);

            _log.Info(string.Format("Path: {0}", path));
        }
 public ListingLineProcessing(ParseContext parseContext,
                              ITime time,
                              bool canCreateStyleInfo)
 {
     _log                 = parseContext.Log;
     _companyId           = parseContext.CompanyId;
     _styleManager        = parseContext.StyleManager;
     _syncInfo            = parseContext.SyncInformer;
     _notificationService = parseContext.NotificationService;
     _styleHistoryService = parseContext.StyleHistoryService;
     _itemHistoryService  = parseContext.ItemHistoryService;
     _actionService       = parseContext.ActionService;
     _time                = time;
     _canCreateStyleInfo  = canCreateStyleInfo;
 }
Пример #5
0
        public long Apply(IUnitOfWork db,
                          IStyleHistoryService styleHistory,
                          DateTime when,
                          long?by)
        {
            var style = db.Styles.Get(StyleId);

            style.UpdateDate = when;
            style.UpdatedBy  = by;

            style.ReSaveDate = when;
            style.ReSaveBy   = by;

            StyleViewModel.UpdateLocations(db, styleHistory, StyleId, Locations, when, by);

            return(StyleId);
        }
        public CallShopifyProcessing(ILogService log,
                                     ITime time,
                                     ICacheService cacheService,
                                     IEmailService emailService,
                                     IDbFactory dbFactory,
                                     IStyleHistoryService styleHistoryService)
        {
            _dbFactory           = dbFactory;
            _cacheService        = cacheService;
            _barcodeService      = new BarcodeService(log, time, dbFactory);
            _log                 = log;
            _time                = time;
            _emailService        = emailService;
            _styleHistoryService = styleHistoryService;

            var itemHistoryService = new ItemHistoryService(_log, _time, _dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
Пример #7
0
        public void UpdateLocationsForStyle(IStyleHistoryService styleHistory,
                                            long styleId,
                                            IList <StyleLocationDTO> locations,
                                            DateTime when,
                                            long?by)
        {
            var dbExistLocations = GetFiltered(l => l.StyleId == styleId).ToList();
            var newLocations     = locations.Where(l => l.Id == 0).ToList();

            foreach (var dbLoc in dbExistLocations)
            {
                var existLoc = locations.FirstOrDefault(l => l.Id == dbLoc.Id);
                if (existLoc != null)
                {
                    bool hasChanges = dbLoc.Isle != existLoc.Isle ||
                                      dbLoc.Section != existLoc.Section ||
                                      dbLoc.Shelf != existLoc.Shelf ||
                                      dbLoc.IsDefault != existLoc.IsDefault;

                    if (hasChanges)
                    {
                        styleHistory.AddRecord(styleId, StyleHistoryHelper.LocationKey,
                                               dbLoc.Isle + "/" + dbLoc.Section + "/" + dbLoc.Shelf,
                                               existLoc.Isle + "/" + existLoc.Section + "/" + existLoc.Shelf,
                                               by);

                        dbLoc.Isle      = existLoc.Isle;
                        dbLoc.Section   = existLoc.Section;
                        dbLoc.Shelf     = existLoc.Shelf;
                        dbLoc.IsDefault = existLoc.IsDefault;

                        dbLoc.SortIsle    = existLoc.SortIsle;
                        dbLoc.SortSection = existLoc.SortSection;
                        dbLoc.SortShelf   = existLoc.SortShelf;

                        dbLoc.UpdateDate = when;
                        dbLoc.UpdatedBy  = by;
                    }
                }
                else
                {
                    styleHistory.AddRecord(styleId, StyleHistoryHelper.LocationKey,
                                           dbLoc.Isle + "/" + dbLoc.Section + "/" + dbLoc.Shelf,
                                           null,
                                           by);
                    Remove(dbLoc);
                }
            }

            foreach (var newLoc in newLocations)
            {
                styleHistory.AddRecord(styleId, StyleHistoryHelper.LocationKey,
                                       null,
                                       newLoc.Isle + "/" + newLoc.Section + "/" + newLoc.Shelf,
                                       by);

                Add(new StyleLocation()
                {
                    StyleId   = styleId,
                    Isle      = newLoc.Isle,
                    Section   = newLoc.Section,
                    Shelf     = newLoc.Shelf,
                    IsDefault = newLoc.IsDefault,

                    SortIsle    = newLoc.SortIsle,
                    SortSection = newLoc.SortSection,
                    SortShelf   = newLoc.SortShelf,

                    CreateDate = when,
                    CreatedBy  = by
                });
            }

            unitOfWork.Commit();
        }
Пример #8
0
        public void Update(IUnitOfWork db,
                           ILogService log,
                           IPriceManager priceManager,
                           IStyleHistoryService styleHistoryService,
                           DateTime when,
                           long?by)
        {
            log.Info("ItemViewModel.Update begin");
            var item    = db.Items.GetAll().FirstOrDefault(i => i.Id == ItemId);
            var listing = db.Listings.GetFiltered(l => l.Id == ListingEntityId).FirstOrDefault();

            if (item != null)
            {
                if (listing != null && !listing.IsFBA)
                {
                    //NOTE: only when we have in DB empty Parent ASIN and came not empty update them. Then create Parent ASIN if not exist
                    if (String.IsNullOrEmpty(item.ParentASIN) && !String.IsNullOrEmpty(ParentASIN))
                    {
                        item.ParentASIN = ParentASIN;

                        db.ParentItems.FindOrCreateForItem(item, when);
                    }

                    log.Info("Item Before: " + item);
                    item.Barcode = Barcode;

                    var style      = db.Styles.GetActiveByStyleIdAsDto(StyleString);
                    var newStyleId = style != null ? style.Id : (long?)null;
                    if (item.StyleId != newStyleId)
                    {
                        if (newStyleId.HasValue)
                        {
                            styleHistoryService.AddRecord(newStyleId.Value,
                                                          StyleHistoryHelper.AttachListingKey,
                                                          item.StyleItemId,
                                                          item.Market + ":" + item.MarketplaceId,
                                                          StyleItemId,
                                                          item.Id.ToString() + ":" + item.ASIN,
                                                          null);
                        }

                        if (item.StyleId.HasValue)
                        {
                            styleHistoryService.AddRecord(item.StyleId.Value,
                                                          StyleHistoryHelper.DetachListingKey,
                                                          item.StyleItemId,
                                                          item.Market + ":" + item.MarketplaceId,
                                                          StyleItemId,
                                                          item.Id.ToString(),
                                                          null);
                        }
                    }

                    item.StyleString = StyleString;
                    item.StyleId     = newStyleId;
                    item.StyleItemId = StyleItemId;

                    item.UseStyleImage = UseStyleImage;

                    item.UpdateDate = when;
                    item.UpdatedBy  = by;
                    log.Info("Item After: " + item);
                }
            }

            if (listing != null)
            {
                log.Info("Listing Before: " + listing);

                listing.IsPrime = IsPrime;

                if (listing.CurrentPrice != ItemCurrentPrice)
                {
                    var oldPrice = listing.CurrentPrice;

                    listing.PriceUpdateRequested = true;
                    listing.CurrentPrice         = ItemCurrentPrice;
                    listing.CurrentPriceInUSD    = PriceHelper.RougeConvertToUSD(listing.CurrentPriceCurrency, ItemCurrentPrice);

                    if (listing.IsFBA)
                    {
                        listing.AutoAdjustedPrice = null;
                    }

                    if (listing.BusinessPrice.HasValue)
                    {
                        listing.BusinessPrice = listing.CurrentPrice;
                    }

                    priceManager.LogListingPrice(db,
                                                 PriceChangeSourceType.EnterNewPrice,
                                                 listing.Id,
                                                 listing.SKU,
                                                 listing.CurrentPrice,
                                                 oldPrice,
                                                 when,
                                                 by);
                }


                //NOTE: Always force send updates to Amazon
                listing.PriceUpdateRequested = true;

                if (!listing.IsFBA)
                {
                    if (DisplayQuantity != listing.DisplayQuantity)
                    {
                        listing.QuantityUpdateRequested     = true;
                        listing.QuantityUpdateRequestedDate = when;
                        listing.DisplayQuantity             = DisplayQuantity;
                    }

                    if (listing.OnHold != OnHold)
                    {
                        listing.QuantityUpdateRequested     = true;
                        listing.QuantityUpdateRequestedDate = when;
                        listing.OnHold = OnHold;
                    }

                    //NOTE: Always force send updates to Amazon
                    listing.QuantityUpdateRequested     = true;
                    listing.QuantityUpdateRequestedDate = when;
                }

                listing.UpdateDate = when;
                listing.UpdatedBy  = by;

                log.Info("Listing After: " + listing);
            }
            db.Commit();
            log.Info("ItemViewModel.Update end");
        }
Пример #9
0
        public long Apply(IUnitOfWork db,
                          ICacheService cache,
                          IQuantityManager quantityManager,
                          IStyleHistoryService styleHistory,
                          ISystemActionService actionService,
                          DateTime when,
                          long?by)
        {
            var style = db.Styles.Get(StyleId);

            style.UpdateDate = when;
            style.UpdatedBy  = by;

            style.ReSaveDate = when;
            style.ReSaveBy   = by;

            StyleViewModel.UpdateLocations(db, styleHistory, StyleId, Locations, when, by);

            var wasAnyChanges = false;

            if (Sizes != null && Sizes.Any())
            {
                var styleItems      = db.StyleItems.GetFiltered(si => si.StyleId == StyleId).ToList();
                var styleItemCaches = db.StyleItemCaches.GetFiltered(si => si.StyleId == StyleId).ToList();

                foreach (var size in Sizes)  //Update quantity (marking when/by)
                {
                    //int? oldQuantity = null;
                    //int? newQuantity = null;
                    string tag        = null;
                    bool   wasChanged = false;

                    var styleItem      = styleItems.FirstOrDefault(si => si.Id == size.StyleItemId);
                    var styleItemCache = styleItemCaches.FirstOrDefault(sic => sic.Id == size.StyleItemId);

                    if (styleItem != null)
                    {
                        if (size.UseBoxQuantity)
                        {
                            if (styleItem.Quantity != null)
                            {
                                var oldQuantity = styleItem.Quantity;
                                var newQuantity = size.BoxQuantity;
                                tag = size.BoxQuantitySetDate.ToString();

                                styleItem.Quantity        = null;
                                styleItem.QuantitySetDate = null;
                                styleItem.QuantitySetBy   = null;
                                //styleItem.RestockDate = null;
                                wasChanged = true;

                                quantityManager.LogStyleItemQuantity(db,
                                                                     styleItem.Id,
                                                                     newQuantity,
                                                                     oldQuantity,
                                                                     QuantityChangeSourceType.UseBoxQuantity,
                                                                     tag,
                                                                     null,
                                                                     null,
                                                                     when,
                                                                     by);
                            }
                        }

                        if (size.NewRestockDate.HasValue &&
                            styleItem.RestockDate != size.NewRestockDate)
                        {
                            styleHistory.AddRecord(styleItem.StyleId,
                                                   StyleHistoryHelper.RestockDateKey,
                                                   DateHelper.ToDateTimeString(styleItem.RestockDate),
                                                   StringHelper.JoinTwo("-", styleItem.Size, styleItem.Color),
                                                   DateHelper.ToDateTimeString(size.NewRestockDate),
                                                   styleItem.Id.ToString(),
                                                   by);

                            styleItem.RestockDate = size.NewRestockDate;
                            wasChanged            = true;
                        }

                        if (size.NewManuallyQuantity.HasValue)
                        {
                            var operationType = size.NewManuallyQuantity.Value < 0 ? QuantityOperationType.Lost : QuantityOperationType.AddManually;

                            var quantityOperation = new QuantityOperationDTO()
                            {
                                Type            = (int)operationType,
                                QuantityChanges = new List <QuantityChangeDTO>()
                                {
                                    new QuantityChangeDTO()
                                    {
                                        StyleId     = style.Id,
                                        StyleItemId = styleItem.Id,
                                        Quantity    = -1 * size.NewManuallyQuantity.Value,
                                        //NOTE: we need to change sign to opposite because we substract quantity operataions from inventory
                                    }
                                },
                                Comment = "From style quantity dialog",
                            };

                            quantityManager.AddQuantityOperation(db,
                                                                 quantityOperation,
                                                                 when,
                                                                 by);

                            //NOTE: Hot updating the cache (only for first few seconds to display the updates before recalculation)
                            if (styleItemCache != null)
                            {
                                styleItemCache.SpecialCaseQuantityFromDate += -1 * size.NewManuallyQuantity.Value;
                                styleItemCache.TotalSpecialCaseQuantity    += -1 * size.NewManuallyQuantity.Value;
                            }

                            wasChanged = true;
                        }

                        if (size.IsRemoveRestockDate == true)
                        {
                            styleItem.RestockDate = null;

                            wasChanged = true;
                        }

                        if (size.OnHold != styleItem.OnHold)
                        {
                            quantityManager.LogStyleItemQuantity(db,
                                                                 styleItem.Id,
                                                                 size.OnHold ? 0 : styleItem.Quantity,
                                                                 size.OnHold ? styleItem.Quantity : 0,
                                                                 QuantityChangeSourceType.OnHold,
                                                                 size.OnHold.ToString(),
                                                                 null,
                                                                 null,
                                                                 when,
                                                                 by);
                            styleItem.OnHold = size.OnHold;

                            wasChanged = true;
                        }
                    }

                    if (wasChanged)
                    {
                        db.Commit();
                        wasAnyChanges = true;
                    }
                }
            }

            //NOTE: always update cache
            cache.RequestStyleIdUpdates(db,
                                        new List <long>()
            {
                StyleId
            },
                                        UpdateCacheMode.IncludeChild,
                                        AccessManager.UserId);

            if (wasAnyChanges)
            {
                db.Commit();

                SystemActionHelper.RequestQuantityDistribution(db, actionService, StyleId, by);
            }

            return(StyleId);
        }
Пример #10
0
        public void Setup()
        {
            Database.SetInitializer <AmazonContext>(null);
            XmlConfigurator.Configure(new FileInfo(AppSettings.log4net_Config));

            _dbFactory = new DbFactory();
            _time      = new TimeService(_dbFactory);
            _settings  = new SettingsService(_dbFactory);

            _styleHistoryService = new StyleHistoryService(_log, _time, _dbFactory);
            _styleManager        = new StyleManager(_log, _time, _styleHistoryService);
            _actionService       = new SystemActionService(_log, _time);
            _quantityManager     = new QuantityManager(_log, _time);
            _priceManager        = new PriceManager(_log, _time, _dbFactory, _actionService, _settings);
            _cacheService        = new CacheService(_log, _time, _actionService, _quantityManager);
            _barcodeService      = new BarcodeService(_log, _time, _dbFactory);
            _weightService       = new WeightService();

            IEmailSmtpSettings smtpSettings = new EmailSmtpSettings();

            using (var db = new UnitOfWork())
            {
                _company = db.Companies.GetFirstWithSettingsAsDto();

                if (AppSettings.IsDebug)
                {
                    smtpSettings = SettingsBuilder.GetSmtpSettingsFromAppSettings();
                }
                else
                {
                    smtpSettings = SettingsBuilder.GetSmtpSettingsFromCompany(_company);
                }

                _addressService = AddressService.Default;
                _emailService   = new EmailService(_log, smtpSettings, _addressService);

                //todo check itemHist
                _autoCreateNonameListingService = new AutoCreateNonameListingService(_log,
                                                                                     _time,
                                                                                     _dbFactory,
                                                                                     _cacheService,
                                                                                     _barcodeService,
                                                                                     _emailService, null,
                                                                                     AppSettings.IsDebug);

                var marketplaces = new MarketplaceKeeper(_dbFactory, true);
                marketplaces.Init();

                var shipmentPrividers = db.ShipmentProviders.GetByCompanyId(_company.Id);

                var apiFactory = new MarketFactory(marketplaces.GetAll(), _time, _log, _dbFactory, AppSettings.JavaPath);

                var weightService = new WeightService();

                var serviceFactory = new ServiceFactory();
                var rateProviders  = serviceFactory.GetShipmentProviders(_log,
                                                                         _time,
                                                                         _dbFactory,
                                                                         weightService,
                                                                         shipmentPrividers,
                                                                         null,
                                                                         null,
                                                                         null,
                                                                         null);

                _magentoApi    = (Magento20MarketApi)apiFactory.GetApi(_company.Id, MarketType.Magento, MarketplaceKeeper.ShopifyDWS);
                _shopifyDWSApi = (ShopifyApi)apiFactory.GetApi(_company.Id, MarketType.Shopify, MarketplaceKeeper.ShopifyDWS);
                _eBayApi       = (eBayApi)apiFactory.GetApi(_company.Id, MarketType.eBay, "");
                _amazonApi     = (AmazonApi)apiFactory.GetApi(_company.Id, MarketType.Amazon, MarketplaceKeeper.AmazonComMarketplaceId);
                _walmartApi    = (WalmartApi)apiFactory.GetApi(_company.Id, MarketType.Walmart, "");
            }
        }