Exemplo n.º 1
0
        public CallRateProcessing(
            CompanyDTO company,
            ILogService log,
            IDbFactory dbFactory,
            ITime time)
        {
            _company       = company;
            _log           = log;
            _time          = time;
            _dbFactory     = dbFactory;
            _weightService = new WeightService();

            var messageService = new SystemMessageService(log, time, dbFactory);
            var serviceFactory = new ServiceFactory();
            var actionService  = new SystemActionService(log, time);
            var rateProviders  = serviceFactory.GetShipmentProviders(log,
                                                                     time,
                                                                     dbFactory,
                                                                     _weightService,
                                                                     company.ShipmentProviderInfoList,
                                                                     null,
                                                                     null,
                                                                     null,
                                                                     null);

            _rateService = new RateService(dbFactory,
                                           log,
                                           time,
                                           _weightService,
                                           messageService,
                                           company,
                                           actionService,
                                           rateProviders);
        }
Exemplo n.º 2
0
        public static IList <OrderInfoViewModel> GetAll(IUnitOfWork db,
                                                        ILogService log,
                                                        IWeightService weightService,
                                                        int?batchId)
        {
            var filter = new OrderSearchFilter();

            if (!batchId.HasValue)
            {
                filter.OrderStatus = OrderStatusEnumEx.AllUnshipped;
            }
            else
            {
                filter.OrderStatus = OrderStatusEnumEx.AllUnshippedWithShipped;
                filter.BatchId     = batchId.Value;
            }
            filter.IncludeNotify    = true;
            filter.IncludeMailInfos = true;

            IList <DTOOrder> orders = db.ItemOrderMappings
                                      .GetFilteredOrderInfos(weightService, filter)
                                      .ToList();

            return(orders.Select(o => new OrderInfoViewModel(o))
                   .Where(o => !o.HasAllLabels && !o.HasMailLabels)
                   .ToList());
        }
Exemplo n.º 3
0
        public CallSupplieroasisProcessing(ILogService log,
                                           ITime time,
                                           ICacheService cacheService,
                                           IEmailService emailService,
                                           IDbFactory dbFactory,
                                           CompanyDTO company)
        {
            _dbFactory             = dbFactory;
            _cacheService          = cacheService;
            _barcodeService        = new BarcodeService(log, time, dbFactory);
            _trackingNumberService = new TrackingNumberService(log, time, dbFactory);
            _log          = log;
            _time         = time;
            _emailService = emailService;
            _company      = company;

            _weightService  = new WeightService();
            _messageService = new SystemMessageService(_log, _time, dbFactory);
            _actionService  = new SystemActionService(_log, _time);
            _htmlScraper    = new HtmlScraperService(log, time, dbFactory);

            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, _barcodeService, _emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 4
0
 public WooCommerceOrdersSynchronizer(ILogService log,
                                      CompanyDTO company,
                                      ISyncInformer syncInfo,
                                      IList <IShipmentApi> rateProviders,
                                      ICompanyAddressService companyAddress,
                                      ITime time,
                                      IWeightService weightService,
                                      ISystemMessageService messageService) : base(log,
                                                                                   null,
                                                                                   company,
                                                                                   null,
                                                                                   syncInfo,
                                                                                   rateProviders,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   null,
                                                                                   companyAddress,
                                                                                   time,
                                                                                   weightService,
                                                                                   messageService)
 {
 }
Exemplo n.º 5
0
 public WooCommerceOrdersSynchronizer(ILogService log,
                                      IMarketApi api,
                                      CompanyDTO company,
                                      ISettingsService settings,
                                      ISyncInformer syncInfo,
                                      IList <IShipmentApi> rateProviders,
                                      IQuantityManager quantityManager,
                                      IEmailService emailService,
                                      IOrderValidatorService validatorService,
                                      IOrderHistoryService orderHistoryService,
                                      ICacheService cacheService,
                                      ISystemActionService systemAction,
                                      ICompanyAddressService companyAddress,
                                      ITime time,
                                      IWeightService weightService,
                                      ISystemMessageService messageService) : base(log,
                                                                                   api,
                                                                                   company,
                                                                                   settings,
                                                                                   syncInfo,
                                                                                   rateProviders,
                                                                                   quantityManager,
                                                                                   emailService,
                                                                                   validatorService,
                                                                                   orderHistoryService,
                                                                                   cacheService,
                                                                                   systemAction,
                                                                                   companyAddress,
                                                                                   time,
                                                                                   weightService,
                                                                                   messageService)
 {
 }
Exemplo n.º 6
0
        public static PrintLabelResult GenerateLabel(
            IUnitOfWork db,
            ILabelService labelService,
            IWeightService weightService,
            IShippingService shippingService,
            MailViewModel model,
            DateTime when,
            long?by)
        {
            var shippingMethod = db.ShippingMethods.GetByIdAsDto(model.ShippingMethodSelected.Value);

            var orderItems = model.Items.Select(i => i.GetItemDto()).ToList() ?? new List <DTOOrderItem>();

            //Fill with additional data
            MailViewModel.FillItemsWithAdditionalInfo(db, weightService, model.OrderID, orderItems);

            var mailInfo = new MailLabelDTO
            {
                FromAddress = model.FromAddress.GetAddressDto(),
                ToAddress   = model.ToAddress.GetAddressDto(),

                Notes        = model.Notes,
                Instructions = model.Instructions,
                OrderId      = model.OrderID,
                WeightLb     = model.WeightLb,
                WeightOz     = model.WeightOz,

                PackageHeight = model.PackageHeight,
                PackageLength = model.PackageLength,
                PackageWidth  = model.PackageWidth,

                IsAddressSwitched         = model.IsAddressSwitched,
                IsUpdateRequired          = model.UpdateAmazon,
                IsCancelCurrentOrderLabel = model.CancelCurrentOrderLabel,

                IsInsured          = model.IsInsured,
                IsSignConfirmation = model.IsSignConfirmation,
                TotalPrice         = model.TotalPrice,
                TotalPriceCurrency = model.TotalPriceCurrency,

                ShippingMethod       = shippingMethod,
                ShipmentProviderType = shippingMethod.ShipmentProviderType,

                Items = orderItems,

                MarketplaceCode = model.MarketplaceCode,
                Reason          = model.ReasonCode ?? 0,

                BoughtInTheCountry = MarketBaseHelper.GetMarketCountry((MarketType)model.Market, model.MarketplaceId),
            };

            return(labelService.PrintMailLabel(db,
                                               shippingService,
                                               mailInfo,
                                               when,
                                               by,
                                               AppSettings.LabelDirectory,
                                               AppSettings.TemplateDirectory,
                                               AppSettings.IsSampleLabels));
        }
Exemplo n.º 7
0
 public BatchManager(ILogService log,
                     ITime time,
                     IOrderHistoryService orderHistoryService,
                     IWeightService weightService)
 {
     _log                 = log;
     _time                = time;
     _weightService       = weightService;
     _orderHistoryService = orderHistoryService;
 }
 public GrouponProductFeed(ILogService log,
                           ITime time,
                           IDbFactory dbFactory,
                           IWeightService weightService,
                           string grouponImageBaseUrl,
                           string grouponImageDirectory)
 {
     _time                  = time;
     _log                   = log;
     _dbFactory             = dbFactory;
     _weightService         = weightService;
     _grouponImageBaseUrl   = grouponImageBaseUrl;
     _grouponImageDirectory = grouponImageDirectory;
 }
Exemplo n.º 9
0
        public CallGrouponProcessing(IDbFactory dbFactory,
                                     ICacheService cacheService,
                                     IEmailService emailService,
                                     ILogService log,
                                     ITime time)
        {
            _dbFactory     = dbFactory;
            _log           = log;
            _time          = time;
            _weightService = new WeightService();
            var barcodeService     = new BarcodeService(log, time, dbFactory);
            var itemHistoryService = new ItemHistoryService(log, time, dbFactory);

            _autoCreateListingService = new AutoCreateNonameListingService(_log, _time, dbFactory, cacheService, barcodeService, emailService, itemHistoryService, AppSettings.IsDebug);
        }
Exemplo n.º 10
0
        public IList <IShipmentApi> GetShipmentProviders(ILogService log,
                                                         ITime time,
                                                         IDbFactory dbFactory,
                                                         IWeightService weightService,
                                                         IList <ShipmentProviderDTO> shipmentProviderInfos,
                                                         string defaultCustomType,
                                                         string outputDirectory,
                                                         string reserveDirectory,
                                                         string templateDirectory)
        {
            var results          = new List <IShipmentApi>();
            var providerTypeList = new List <ShipmentProviderType>()
            {
                ShipmentProviderType.Stamps,
                ShipmentProviderType.StampsPriority,
                ShipmentProviderType.Amazon,
                ShipmentProviderType.Dhl,
                ShipmentProviderType.DhlECom,
                ShipmentProviderType.IBC,
                ShipmentProviderType.SkyPostal,
                ShipmentProviderType.FIMS,
                ShipmentProviderType.FedexSmartPost,
                ShipmentProviderType.FedexOneRate,
                ShipmentProviderType.FedexGeneral
            };

            foreach (var providerType in providerTypeList)
            {
                IShipmentApi provider = null;
                provider = GetShipmentProviderByType(providerType,
                                                     log,
                                                     time,
                                                     dbFactory,
                                                     weightService,
                                                     shipmentProviderInfos,
                                                     defaultCustomType,
                                                     outputDirectory,
                                                     reserveDirectory,
                                                     templateDirectory);

                if (provider != null)
                {
                    results.Add(provider);
                }
            }

            return(results);
        }
 public DhlECommerceSwitchService(ILogService log,
                                  ITime time,
                                  CompanyDTO company,
                                  IDbFactory dbFactory,
                                  IEmailService emailService,
                                  IWeightService weightService,
                                  ISystemMessageService messageService)
 {
     _log            = log;
     _time           = time;
     _company        = company;
     _dbFactory      = dbFactory;
     _emailService   = emailService;
     _weightService  = weightService;
     _messageService = messageService;
 }
        public List <MessageString> ProcessApplyResult(ApplyOrderResult applyResult,
                                                       IUnitOfWork db,
                                                       ILogService log,
                                                       ITime time,
                                                       IOrderSynchronizer synchronizer,
                                                       AddressChecker addressChecker,
                                                       IOrderHistoryService orderHistoryService,
                                                       IWeightService weightService,
                                                       long?by)
        {
            var results = new List <MessageString>();

            if (applyResult.RateRecalcRequested)
            {
                var dtoOrder = db.ItemOrderMappings.GetOrderWithItems(weightService, OrderId, unmaskReferenceStyle: false, includeSourceItems: true);

                try
                {
                    RetryHelper.ActionWithRetries(() => synchronizer.UIUpdate(db,
                                                                              dtoOrder,
                                                                              isForceOverride: false,
                                                                              keepActiveShipping: true,
                                                                              keepCustomShipping: applyResult.ShipmentProviderChanged ? false : true,
                                                                              switchToMethodId: null),
                                                  log,
                                                  2,
                                                  300,
                                                  RetryModeType.Normal,
                                                  true);

                    orderHistoryService.AddRecord(dtoOrder.Id, OrderHistoryHelper.RecalculateRatesKey, null, true, by);
                }
                catch (Exception ex)
                {
                    results.Add(MessageString.Error("", "An unexpected error has occurred. Please try again. Detail: " + ex.Message));
                }
            }

            if (applyResult.AddressValidationRequested)
            {
                addressChecker.UpdateOrderAddressValidationStatus(db, EntityId, null);
            }

            return(results);
        }
Exemplo n.º 13
0
 public RateService(IDbFactory dbFactory,
                    ILogService log,
                    ITime time,
                    IWeightService weightService,
                    ISystemMessageService messageService,
                    CompanyDTO company,
                    ISystemActionService actionService,
                    IList <IShipmentApi> rateProviders)
 {
     _dbFactory      = dbFactory;
     _log            = log;
     _time           = time;
     _weightService  = weightService;
     _messageService = messageService;
     _actionService  = actionService;
     _company        = company;
     _rateProviders  = rateProviders;
 }
Exemplo n.º 14
0
        public ProfitService(
            IEmployeeRepository employeeRepository,
            IConfiguration configuration,
            ILogger <ProfitService> logger,
            IWeightService <OccupationAreaWeight> occupationAreaWeightService,
            IWeightService <SalaryWeight> salaryWeightRepositoryService,
            IWeightService <WorkYearsWeight> workYearsWeightService
            )
        {
            Configuration = configuration;
            MinimumSalary = Configuration["MinimumSalary"];

            _employeeRepository = employeeRepository;
            _logger             = logger;

            OccupationAreService   = occupationAreaWeightService;
            SalaryWeightService    = salaryWeightRepositoryService;
            WorkYearsWeightService = workYearsWeightService;
        }
 public LabelAutoBuyService(IDbFactory dbFactory,
                            ILogService log,
                            ITime time,
                            IBatchManager batchManager,
                            ILabelBatchService labelBatchService,
                            ISystemActionService actionService,
                            IEmailService emailService,
                            IWeightService weightService,
                            long companyId)
 {
     _dbFactory         = dbFactory;
     _log               = log;
     _time              = time;
     _batchManager      = batchManager;
     _labelBatchService = labelBatchService;
     _actionService     = actionService;
     _emailService      = emailService;
     _companyId         = companyId;
     _weightService     = weightService;
 }
Exemplo n.º 16
0
        public static ShippingMethodViewModel GetQuickPrintLabelRate(IUnitOfWork db,
                                                                     IDbFactory dbFactory,
                                                                     IServiceFactory serviceFactory,
                                                                     IShippingService shippingService,
                                                                     CompanyDTO company,
                                                                     ILogService log,
                                                                     ITime time,
                                                                     IWeightService weightService,
                                                                     string orderNumber)
        {
            var companyAddress = new CompanyAddressService(company);

            var model = MailViewModel.GetByOrderId(db, weightService, orderNumber);

            model.IsAddressSwitched  = true;
            model.FromAddress        = model.ToAddress;
            model.ToAddress          = MailViewModel.GetFromAddress(companyAddress.GetReturnAddress(MarketIdentifier.Empty()), MarketplaceType.Amazon);
            model.ShipmentProviderId = (int)ShipmentProviderType.Stamps;
            model.ReasonCode         = (int)MailLabelReasonCodes.ReturnLabelReasonCode;

            var rateProvider = serviceFactory.GetShipmentProviderByType((ShipmentProviderType)model.ShipmentProviderId,
                                                                        log,
                                                                        time,
                                                                        dbFactory,
                                                                        weightService,
                                                                        company.ShipmentProviderInfoList,
                                                                        null,
                                                                        null,
                                                                        null,
                                                                        null);

            var shippingOptionsResult           = model.GetShippingOptionsModel(db, time, log, rateProvider, shippingService, weightService);
            ShippingMethodViewModel chipestRate = null;

            if (shippingOptionsResult.IsSuccess)
            {
                chipestRate = shippingOptionsResult.Data.OrderBy(o => o.Rate).FirstOrDefault();
            }
            return(chipestRate);
        }
        public CallResult <List <ShippingMethodViewModel> > GetShippingOptionsModel(IUnitOfWork db,
                                                                                    ITime time,
                                                                                    ILogService log,
                                                                                    IShipmentApi rateProvider,
                                                                                    IWeightService weightService,
                                                                                    IShippingService shippingService,
                                                                                    IList <OrderItemRateInfo> orderItems)
        {
            var result = new CallResult <List <ShippingMethodViewModel> >();

            var fromAddress = FromAddress.GetAddressDto();
            var toAddress   = ToAddress.GetAddressDto();

            if (AddressHelper.IsEmpty(fromAddress) ||
                AddressHelper.IsEmpty(toAddress))
            {
                result.Status  = CallStatus.Fail;
                result.Message = "Empty from/to address";
            }


            result = GetShippingOptionsWithRate(db,
                                                log,
                                                time,
                                                rateProvider,
                                                shippingService,
                                                fromAddress,
                                                toAddress,
                                                time.GetAppNowTime(),
                                                WeightLb ?? 0,
                                                (decimal)(WeightOz ?? 0),
                                                0,
                                                new OrderRateInfo()
            {
                Items = orderItems,
            });

            return(result);
        }
        public CallPrintProcessing(
            ILogService log,
            ITime time,
            IDbFactory dbFactory,
            IEmailService emailService,
            CompanyDTO company,
            string outputDirectory,
            string templateDirectory,
            string reserveDirectory)
        {
            _log           = log;
            _time          = time;
            _company       = company;
            _emailService  = emailService;
            _pdfMaker      = new PdfMakerByIText(_log);
            _dbFactory     = dbFactory;
            _weightService = new WeightService();

            _outputDirectory   = outputDirectory;
            _templateDirectory = templateDirectory;
            _reserveDirectory  = reserveDirectory;
        }
Exemplo n.º 19
0
        private static IEnumerable <DTOOrder> GetOrdersWithItemsForPickList(IUnitOfWork db,
                                                                            IWeightService weightService,
                                                                            OrderSearchFilterViewModel search)
        {
            var filter = search.GetModel();

            filter.UnmaskReferenceStyles = true;

            //if (filter.BatchId.HasValue)
            //{
            //    var batchOrderList = db.OrderToBatches.GetViewAllAsDto().Where(o => o.BatchId == filter.BatchId.Value).ToList();
            //    if (batchOrderList.Any()) //Batch created using OrderToBatch
            //    {
            //        filter.EqualOrderIds = batchOrderList.Select(o => o.OrderId).Distinct().ToArray();
            //        filter.BatchId = null;
            //    }
            //}

            var orders = db.ItemOrderMappings.GetFilteredOrdersWithItems(weightService, filter)
                         .ToList();

            return(orders);
        }
Exemplo n.º 20
0
        public LabelBatchService(IDbFactory dbFactory,
                                 ISystemActionService actionService,
                                 ILogService log,
                                 ITime time,
                                 IWeightService weightService,
                                 IServiceFactory serviceFactory,
                                 IEmailService emailService,
                                 IBatchManager batchManager,
                                 IFileMaker pdfMaker,
                                 IAddressService addressService,
                                 IOrderHistoryService orderHistoryService,
                                 string defaultCustomType,
                                 string labelDirectory,
                                 string reserveDirectory,
                                 string templateDirectory,
                                 Config config,
                                 bool isSampleMode)
        {
            _dbFactory           = dbFactory;
            _actionService       = actionService;
            _log                 = log;
            _time                = time;
            _weightService       = weightService;
            _serviceFactory      = serviceFactory;
            _emailService        = emailService;
            _batchManager        = batchManager;
            _pdfMaker            = pdfMaker;
            _addressService      = addressService;
            _orderHistoryService = orderHistoryService;

            _defaultCustomType = defaultCustomType;
            _labelDirectory    = labelDirectory;
            _reserveDirectory  = reserveDirectory;
            _templateDirectory = templateDirectory;
            _config            = config;
            _isSampleMode      = isSampleMode;
        }
Exemplo n.º 21
0
 public WeightController(IWeightService weightService)
 {
     _weightService = weightService;
 }
Exemplo n.º 22
0
        public static OrderQuickSummaryViewModel GetByOrderId(IUnitOfWork db,
                                                              ILogService log,
                                                              IWeightService weightService,
                                                              string orderId)
        {
            DTOOrder order = null;

            if (!String.IsNullOrEmpty(orderId))
            {
                orderId = orderId.RemoveWhitespaces();
                var orderNumber = OrderHelper.RemoveOrderNumberFormat(orderId);
                var filter      = new OrderSearchFilter()
                {
                    EqualOrderNumber = orderNumber,
                    IncludeMailInfos = true,
                    IncludeNotify    = false,

                    UnmaskReferenceStyles = false,
                };

                order = db.ItemOrderMappings
                        .GetFilteredOrdersWithItems(weightService, filter)
                        .FirstOrDefault();
            }

            if (order == null)
            {
                return(null);
            }
            else
            {
                var refundRequestList = RefundViewModel.GetByOrderId(db, order.OrderId);

                var shippingPrice = 0M;

                var activeShippings = order.ShippingInfos.Where(i => i.IsActive).ToList();
                activeShippings.AddRange(order.MailInfos);
                activeShippings = activeShippings.OrderBy(sh => sh.LabelPurchaseDate).ToList();
                //if (order.MailInfos.Any(m => !m.LabelCanceled)
                //    && order.ShippingInfos.All(sh => String.IsNullOrEmpty(sh.LabelPath) || sh.LabelCanceled))
                //{
                //    var mailShipping = order.MailInfos.OrderBy(m => m.LabelPurchaseDate).FirstOrDefault(l => !l.LabelCanceled);
                //    activeShippings = new List<OrderShippingInfoDTO>() { mailShipping };
                //}
                //var mainActiveShipping = activeShippings.FirstOrDefault();
                //var shipmentProviderType = mainActiveShipping != null ? mainActiveShipping.ShipmentProviderType : (int)Core.Models.Settings.ShipmentProviderType.Stamps;
                var address = order.GetAddressDto();

                return(new OrderQuickSummaryViewModel()
                {
                    OrderID = order.OrderId,
                    OrderEntityId = order.Id,
                    OrderDate = order.OrderDate,
                    OrderStatus = order.OrderStatus,
                    Market = (MarketType)order.Market,
                    MarketplaceId = order.MarketplaceId,

                    OrderIsOnHold = order.OnHold,

                    WeightLb = (int)Math.Floor(order.WeightD / 16),
                    WeightOz = order.WeightD % 16,

                    TrackingNumbers = activeShippings.Where(t => !String.IsNullOrEmpty(t.TrackingNumber)).Select(t => new LabelViewModel()
                    {
                        TrackingNumber = t.TrackingNumber,
                        Carrier = t.ShippingMethod.CarrierName,
                        FromType = (LabelFromType)t.LabelFromType,
                        TrackingStatusSource = t.TrackingStateSource,
                        ShippingDate = t.ShippingDate,
                        EstDeliveryDate = t.EstimatedDeliveryDate,
                        ActualDeliveryDate = t.ActualDeliveryDate,
                        LastTrackingStateUpdateDate = t.LastTrackingRequestDate,
                        IsCanceled = t.CancelLabelRequested || t.LabelCanceled,
                        DeliveryStatusMessage = GetDeliveryStatus(order.LatestDeliveryDate,
                                                                  t.ActualDeliveryDate,
                                                                  t.TrackingStateDate,
                                                                  t.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender),
                        ShippingMethodName = t.ShippingMethod != null
                            ? ShippingUtils.PrepareMethodNameToDisplay(t.ShippingMethod.Name, t.DeliveryDaysInfo) : string.Empty,
                        ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)t.ShipmentProviderType),
                    }).ToList(),

                    PriceCurrency = PriceHelper.FormatCurrency(order.TotalPriceCurrency),

                    ExpectedShipDate = order.LatestShipDate,
                    ExpectedDeliveryDate = order.LatestDeliveryDate,

                    //ShippingMethodName = mainActiveShipping != null && mainActiveShipping.ShippingMethod != null
                    //    ? ShippingUtils.PrepareMethodNameToDisplay(mainActiveShipping.ShippingMethod.Name, mainActiveShipping.DeliveryDaysInfo) : string.Empty,
                    //ShippingProviderName = ShipmentProviderHelper.GetName((ShipmentProviderType)shipmentProviderType),
                    //ShippingDate = activeShippings.Where(i => i.IsActive).Max(i => i.ShippingDate),

                    //DeliveryDate = mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null,
                    //DeliveryStatus = GetDeliveryStatus(order.LatestDeliveryDate,
                    //    mainActiveShipping != null ? mainActiveShipping.ActualDeliveryDate : null,
                    //    mainActiveShipping != null ? mainActiveShipping.TrackingStateDate : null,
                    //    mainActiveShipping != null ? mainActiveShipping.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender : false),

                    Refunds = refundRequestList,

                    Items = order.Items.Select(i => new OrderItemViewModel(i, false, false)).ToList(),

                    ToAddress = address,
                });
            }
        }
Exemplo n.º 23
0
        public IShipmentApi GetShipmentProviderByType(
            ShipmentProviderType providerType,
            ILogService log,
            ITime time,
            IDbFactory dbFactory,
            IWeightService weightService,
            IList <ShipmentProviderDTO> shipmentProviderInfos,
            string defaultCustomType,
            string outputDirectory,
            string reserveDirectory,
            string templateDirectory)
        {
            var trackingNumberService    = new TrackingNumberService(log, time, dbFactory);
            var supportedShippingMethods = new List <ShippingMethodDTO>();

            using (var db = dbFactory.GetRDb())
            {
                supportedShippingMethods = db.ShippingMethods
                                           .GetAllAsDto()
                                           .Where(m => m.ShipmentProviderType == (int)providerType &&
                                                  m.IsActive)
                                           .ToList();
            }

            switch (providerType)
            {
            case ShipmentProviderType.Stamps:
                var stampsProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Stamps);
                if (stampsProvider != null)
                {
                    var authList =
                        shipmentProviderInfos.Where(p => p.Type == (int)ShipmentProviderType.Stamps ||
                                                    p.Type == (int)ShipmentProviderType.StampsPriority)
                        .ToList();
                    return(new StampsShipmentApi(stampsProvider.Id,
                                                 (ShipmentProviderType)stampsProvider.Type,
                                                 log,
                                                 time,
                                                 weightService,
                                                 trackingNumberService,
                                                 authList.ToList <IStampsAuthInfo>(),
                                                 LabelFormat.Jpg,
                                                 false,
                                                 "Children Clothes",
                                                 true,
                                                 outputDirectory,
                                                 reserveDirectory,
                                                 false));
                }
                return(null);

            case ShipmentProviderType.StampsPriority:
                var stampsPriorityProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.StampsPriority);
                if (stampsPriorityProvider != null)
                {
                    var authList =
                        shipmentProviderInfos.Where(p => p.Type == (int)ShipmentProviderType.Stamps ||
                                                    p.Type == (int)ShipmentProviderType.StampsPriority)
                        .ToList();
                    return(new StampsShipmentApi(stampsPriorityProvider.Id,
                                                 (ShipmentProviderType)stampsPriorityProvider.Type,
                                                 log,
                                                 time,
                                                 weightService,
                                                 trackingNumberService,
                                                 authList.ToList <IStampsAuthInfo>(),
                                                 LabelFormat.Jpg,
                                                 false,
                                                 "Children Clothes",
                                                 true,
                                                 outputDirectory,
                                                 reserveDirectory,
                                                 false));
                }
                return(null);

            case ShipmentProviderType.Amazon:
                var amazonProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Amazon);
                if (amazonProvider != null)
                {
                    return(new AmazonShipmentApi(amazonProvider.Id,
                                                 log,
                                                 time,
                                                 weightService,
                                                 supportedShippingMethods,
                                                 amazonProvider.Key1,
                                                 amazonProvider.Key2,
                                                 amazonProvider.Password,
                                                 amazonProvider.StampUsername,
                                                 amazonProvider.EndPointUrl,
                                                 outputDirectory,
                                                 reserveDirectory,
                                                 templateDirectory));
                }
                return(null);

            case ShipmentProviderType.Dhl:
                var dhlProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.Dhl);
                if (dhlProvider != null)
                {
                    return(new DhlShipmentApi(dhlProvider.Id,
                                              log,
                                              time,
                                              dhlProvider.EndPointUrl,
                                              dhlProvider.UserName,
                                              dhlProvider.Password,
                                              dhlProvider.Key1,
                                              dhlProvider.Key2,
                                              outputDirectory,
                                              reserveDirectory,
                                              templateDirectory));
                }
                return(null);

            case ShipmentProviderType.DhlECom:
                var dhlEComProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.DhlECom);
                if (dhlEComProvider != null)
                {
                    return(new DhlECommerceShipmentApi(dhlEComProvider.Id,
                                                       log,
                                                       time,
                                                       dbFactory,
                                                       weightService,
                                                       dhlEComProvider.UserName,
                                                       dhlEComProvider.Password,
                                                       dhlEComProvider.Key1,
                                                       dhlEComProvider.Key2,
                                                       dhlEComProvider.Key3,
                                                       defaultCustomType,
                                                       outputDirectory,
                                                       reserveDirectory,
                                                       GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom)?.Token,
                                                       () => GetFreshTokenInfo(dbFactory, ShipmentProviderType.DhlECom),
                                                       (t) => StoreNewTokenInfo(dbFactory, ShipmentProviderType.DhlECom, t)));
                }
                return(null);

            case ShipmentProviderType.IBC:
                var ibcProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.IBC);
                if (ibcProvider != null)
                {
                    return(new IBCShipmentApi(ibcProvider.Id,
                                              log,
                                              time,
                                              dbFactory,
                                              weightService,
                                              PortalEnum.PA,
                                              ibcProvider.EndPointUrl,
                                              ibcProvider.UserName,
                                              ibcProvider.Password,
                                              ibcProvider.Key1,
                                              defaultCustomType,
                                              outputDirectory,
                                              reserveDirectory));
                }
                return(null);

            case ShipmentProviderType.SkyPostal:
                var skyPostalProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)ShipmentProviderType.SkyPostal);
                if (skyPostalProvider != null)
                {
                    return(new SkyPostalShipmentApi(skyPostalProvider.Id,
                                                    log,
                                                    time,
                                                    dbFactory,
                                                    weightService,
                                                    PortalEnum.PA,
                                                    skyPostalProvider.EndPointUrl,
                                                    skyPostalProvider.UserName,
                                                    skyPostalProvider.Password,
                                                    skyPostalProvider.Key1,
                                                    skyPostalProvider.Key2,
                                                    skyPostalProvider.Key3,
                                                    defaultCustomType,
                                                    outputDirectory,
                                                    reserveDirectory));
                }
                return(null);

            case ShipmentProviderType.FedexSmartPost:
            case ShipmentProviderType.FedexOneRate:
            case ShipmentProviderType.FedexGeneral:
                var fedexProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)providerType);
                if (fedexProvider != null)
                {
                    return(new FedexShipmentApi(PortalEnum.PA,
                                                fedexProvider.Id,
                                                log,
                                                time,
                                                weightService,
                                                fedexProvider.EndPointUrl,
                                                fedexProvider.UserName,
                                                fedexProvider.Password,
                                                fedexProvider.Key1,
                                                fedexProvider.Key2,
                                                fedexProvider.Key3,
                                                (FedexRateTypes)Int32.Parse(fedexProvider.Key4),
                                                defaultCustomType,
                                                outputDirectory,
                                                reserveDirectory,
                                                templateDirectory));
                }
                return(null);

            case ShipmentProviderType.FIMS:
                var fimsProvider =
                    shipmentProviderInfos.FirstOrDefault(p => p.Type == (int)providerType);
                if (fimsProvider != null)
                {
                    return(new FIMSShipmentApi(fimsProvider.Id,
                                               log,
                                               time,
                                               fimsProvider.EndPointUrl,
                                               fimsProvider.Key1,
                                               fimsProvider.Key2,
                                               fimsProvider.Key3, //air bill number
                                               defaultCustomType,
                                               outputDirectory,
                                               reserveDirectory,
                                               templateDirectory));
                }
                return(null);
            }
            return(null);
        }
        public static MailViewModel GetByOrderId(IUnitOfWork db,
                                                 IWeightService weightService,
                                                 string id)
        {
            var order = db.Orders.GetMailDTOByOrderId(weightService, id);

            if (order == null)
            {
                return(new MailViewModel
                {
                    ToAddress = new AddressViewModel
                    {
                        Address1 = String.Empty,
                        Address2 = String.Empty,
                        FullName = String.Empty,
                        City = String.Empty,
                        USAState = String.Empty,
                        NonUSAState = String.Empty,
                        Country = String.Empty,
                        Zip = String.Empty,
                        Phone = String.Empty,
                        Email = String.Empty,
                        ShipDate = null
                    },
                    Items = new List <MailItemViewModel>(),
                    MarketplaceCode = 1,
                    Notes = String.Empty,
                    OrderStatus = String.Empty,
                    OrderID = String.Empty,
                    OrderEntityId = null,
                    IsPrime = false,

                    ShipmentProviderId = (int)ShipmentProviderType.Stamps,
                    HasBatchLabels = false,
                    HasMailLabels = false,

                    WeightLb = null,
                    WeightOz = null,
                });
            }
            else
            {
                return(new MailViewModel
                {
                    ToAddress = new AddressViewModel
                    {
                        Address1 = order.ToAddress.FinalAddress1,
                        Address2 = order.ToAddress.FinalAddress2,
                        FullName = order.ToAddress.FinalFullName,
                        City = order.ToAddress.FinalCity,
                        USAState = StringHelper.ToUpper(order.ToAddress.FinalState),
                        NonUSAState = StringHelper.ToUpper(order.ToAddress.FinalState),
                        Country = order.ToAddress.FinalCountry,
                        Zip = order.ToAddress.FinalZip,
                        ZipAddon = order.ToAddress.FinalZipAddon,
                        Phone = order.ToAddress.FinalPhone,
                        Email = order.ToAddress.BuyerEmail,
                        ShipDate = order.ToAddress.ShipDate
                    },
                    MarketplaceCode = 1,
                    Notes = "",

                    Market = order.Market,
                    MarketplaceId = order.MarketplaceId,

                    OrderStatus = order.OrderStatus,
                    OrderEntityId = order.OrderEntityId,
                    OrderID = order.OrderId,
                    IsPrime = order.OrderType == (int)OrderTypeEnum.Prime,
                    RequireAmazonProvider = ShippingUtils.RequireAmazonProvider(order.OrderType,
                                                                                order.Market,
                                                                                order.ToAddress.FinalCountry,
                                                                                order.SourceShippingService),

                    ShipmentProviderId = order.ShipmentProviderType,
                    HasBatchLabels = order.Labels.Any(l => l.LabelFromType == (int)LabelFromType.Batch),
                    HasMailLabels = order.Labels.Any(l => l.LabelFromType == (int)LabelFromType.Mail),

                    WeightLb = order.WeightLb,
                    WeightOz = order.WeightOz,

                    TotalPrice = order.TotalPrice,
                    TotalPriceCurrency = order.TotalPriceCurrency,

                    Items = order.Items.Select(i => new MailItemViewModel(i)).ToList(),

                    IsInsured = order.IsInsured
                });
            }
        }
Exemplo n.º 25
0
        public void Create(ILogService log,
                           ITime time,
                           IQuantityManager quantityManager,
                           IDbFactory dbFactory,
                           IWeightService weightService,
                           IShippingService shippingService,
                           IAutoCreateListingService createListingService,
                           ISettingsService settingService,
                           IEmailService emailService,
                           ISystemActionService actionService,
                           IHtmlScraperService htmlScraper,
                           IOrderHistoryService orderHistory,
                           IPriceService priceService,
                           CompanyDTO company,
                           DateTime when,
                           long?by)
        {
            var syncInfo      = new EmptySyncInformer(log, SyncType.Orders);
            var market        = (int)MarketType.OfflineOrders;
            var marketplaceId = MarketplaceKeeper.ManuallyCreated;

            var orderItems = new List <ListingOrderDTO>();

            using (var db = dbFactory.GetRWDb())
            {
                var index = 1;
                foreach (var item in Items)
                {
                    var dbItem = db.Items.GetAll().FirstOrDefault(i => i.Market == market &&
                                                                  i.MarketplaceId == marketplaceId &&
                                                                  i.StyleItemId == item.StyleItemId);

                    if (dbItem == null)
                    {
                        var itemPrice = item.ItemPrice; // db.Items.GetAllViewActual()
                                                        //.FirstOrDefault(i => i.Market == (int)MarketType.Amazon
                                                        //    && i.MarketplaceId == MarketplaceKeeper.AmazonComMarketplaceId)?.CurrentPrice;

                        log.Info("Request create listing, market=" + market
                                 + ", marketplaceId=" + marketplaceId);

                        IList <MessageString> messages = new List <MessageString>();
                        //Create New
                        var model = createListingService.CreateFromStyle(db,
                                                                         item.StyleId.Value,
                                                                         (MarketType)market,
                                                                         marketplaceId,
                                                                         out messages);

                        model.Variations.ForEach(v => v.CurrentPrice = itemPrice);

                        createListingService.Save(model,
                                                  "",
                                                  db,
                                                  when,
                                                  by);

                        dbItem = db.Items.GetAll().FirstOrDefault(i => i.Market == market &&
                                                                  i.MarketplaceId == marketplaceId &&
                                                                  i.StyleItemId == item.StyleItemId);
                    }

                    var dbListing = db.Listings.GetAll().FirstOrDefault(l => l.Market == market &&
                                                                        l.MarketplaceId == marketplaceId &&
                                                                        l.ItemId == dbItem.Id);

                    orderItems.Add(new ListingOrderDTO()
                    {
                        ASIN            = dbItem.ASIN,
                        SKU             = dbListing.SKU,
                        ItemPaid        = item.ItemPrice,
                        ItemPrice       = item.ItemPrice,
                        ItemGrandPrice  = item.ItemPrice,
                        StyleId         = dbItem.StyleId,
                        StyleID         = dbItem.StyleString,
                        StyleItemId     = dbItem.StyleItemId,
                        Market          = dbItem.Market,
                        MarketplaceId   = dbItem.MarketplaceId,
                        QuantityOrdered = item.Quantity,
                        ItemOrderId     = index.ToString(),
                        SourceListingId = dbListing.Id,
                    });

                    index++;
                }

                OrderNumber = db.Orders.GetAll()
                              .Where(o => o.Market == (int)market &&
                                     o.MarketplaceId == marketplaceId)
                              .OrderByDescending(o => o.Id).FirstOrDefault()?.AmazonIdentifier;

                if (String.IsNullOrEmpty(OrderNumber))
                {
                    OrderNumber = "1000";
                }
                else
                {
                    OrderNumber = ((StringHelper.TryGetInt(OrderNumber) ?? 1000) + 1).ToString();
                }
            }

            var dtoOrder = new DTOOrder()
            {
                Market            = market,
                MarketplaceId     = marketplaceId,
                OrderDate         = OrderDate,
                OrderStatus       = "Unshipped",
                SourceOrderStatus = "Unshipped",
                OrderId           = OrderNumber,
                CustomerOrderId   = OrderNumber,
                MarketOrderId     = OrderNumber,

                AmazonEmail      = ToAddress.Email,
                BuyerEmail       = ToAddress.Email,
                PersonName       = ToAddress.FullName,
                BuyerName        = ToAddress.FullName,
                ShippingAddress1 = ToAddress.Address1,
                ShippingAddress2 = ToAddress.Address2,
                ShippingCity     = ToAddress.City,
                ShippingCountry  = ToAddress.Country,
                ShippingZip      = ToAddress.Zip,
                ShippingZipAddon = ToAddress.ZipAddon,
                ShippingPhone    = ToAddress.Phone,
                ShippingState    = StringHelper.GetFirstNotEmpty(ToAddress.USAState, ToAddress.NonUSAState),

                ShippingPaid  = 0,
                ShippingPrice = 0,
                TotalPaid     = Items.Sum(i => i.ItemPrice),
                TotalPrice    = Items.Sum(i => i.ItemPrice),

                Quantity = Items.Sum(i => i.Quantity),

                InitialServiceType    = ShippingService,
                ShippingService       = ShippingService,
                SourceShippingService = ShippingService,

                Items = orderItems,
            };

            var userOrderApi = new UserOrderApi(new List <DTOOrder>()
            {
                dtoOrder
            });

            var serviceFactory       = new ServiceFactory();
            var addressCheckServices = serviceFactory.GetAddressCheckServices(log,
                                                                              time,
                                                                              dbFactory,
                                                                              company.AddressProviderInfoList);
            var companyAddress = new CompanyAddressService(company);
            var addressService = new AddressService(addressCheckServices, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), companyAddress.GetPickupAddress(MarketIdentifier.Empty()));

            var rateProviders = serviceFactory.GetShipmentProviders(log,
                                                                    time,
                                                                    dbFactory,
                                                                    weightService,
                                                                    company.ShipmentProviderInfoList,
                                                                    null,
                                                                    null,
                                                                    null,
                                                                    null);

            var stampsRateProvider = rateProviders.FirstOrDefault(r => r.Type == ShipmentProviderType.Stamps);

            var validatorService = new OrderValidatorService(log, dbFactory, emailService, settingService, orderHistory, actionService,
                                                             priceService, htmlScraper, addressService, companyAddress.GetReturnAddress(MarketIdentifier.Empty()), stampsRateProvider, time, company);
            var orderHistoryService = new OrderHistoryService(log, time, dbFactory);
            var cacheService        = new CacheService(log, time, actionService, quantityManager);

            using (var db = dbFactory.GetRWDb())
            {
                try
                {
                    var orderSyncFactory = new OrderSyncFactory();
                    var synchronizer     = orderSyncFactory.GetForMarket(userOrderApi,
                                                                         log,
                                                                         company,
                                                                         settingService,
                                                                         syncInfo,
                                                                         rateProviders,
                                                                         quantityManager,
                                                                         emailService,
                                                                         validatorService,
                                                                         orderHistoryService,
                                                                         cacheService,
                                                                         actionService,
                                                                         companyAddress,
                                                                         time,
                                                                         weightService,
                                                                         null);

                    if (!String.IsNullOrEmpty(OrderNumber))
                    {
                        synchronizer.ProcessSpecifiedOrder(db, OrderNumber);
                        Messages.Add(MessageString.Success("The order has been successfully created, order #: " + OrderNumber));
                    }
                }
                catch (Exception ex)
                {
                    Messages.Add(MessageString.Error(ex.Message));
                }
            }
        }
Exemplo n.º 26
0
 public OccupationAreaWeightController(ILogger <OccupationAreaWeightController> logger, IWeightService <OccupationAreaWeight> weightService)
 {
     _weightService = weightService;
     _logger        = logger;
 }
Exemplo n.º 27
0
 public WorkYearsWeightController(ILogger <WorkYearsWeightController> logger, IWeightService <WorkYearsWeight> weightService)
 {
     _weightService = weightService;
     _logger        = logger;
 }
Exemplo n.º 28
0
        public MailLabelDTO GetMailDTOByOrderId(IWeightService weightService, string orderId)
        {
            var query = (from o in unitOfWork.GetSet <Order>()
                         join oi in unitOfWork.GetSet <OrderItem>() on o.Id equals oi.OrderId
                         join l in unitOfWork.GetSet <ViewListing>() on oi.ListingId equals l.Id
                         where (o.AmazonIdentifier == orderId ||
                                o.CustomerOrderId == orderId) &&
                         oi.QuantityOrdered > 0
                         select new MailLabelDTO
            {
                ToAddress = new AddressDTO
                {
                    Address1 = o.ShippingAddress1,
                    Address2 = o.ShippingAddress2,
                    City = o.ShippingCity,
                    Country = o.ShippingCountry,
                    State = o.ShippingState,
                    Zip = o.ShippingZip,
                    ZipAddon = o.ShippingZipAddon,

                    FullName = o.PersonName,
                    Phone = o.ShippingPhone,
                    BuyerEmail = o.BuyerEmail,

                    IsManuallyUpdated = o.IsManuallyUpdated,
                    ManuallyFullName = o.ManuallyPersonName,
                    ManuallyAddress1 = o.ManuallyShippingAddress1,
                    ManuallyAddress2 = o.ManuallyShippingAddress2,
                    ManuallyCity = o.ManuallyShippingCity,
                    ManuallyCountry = o.ManuallyShippingCountry,
                    ManuallyPhone = o.ManuallyShippingPhone,
                    ManuallyState = o.ManuallyShippingState,
                    ManuallyZip = o.ManuallyShippingZip,
                    ManuallyZipAddon = o.ManuallyShippingZipAddon,
                },
                OrderEntityId = o.Id,
                OrderId = o.AmazonIdentifier,
                CustomerOrderId = o.CustomerOrderId,
                Market = o.Market,
                MarketplaceId = o.MarketplaceId,
                OrderStatus = o.OrderStatus,
                ShipmentProviderType = o.ShipmentProviderType,
                OrderType = o.OrderType,
                SourceShippingService = o.SourceShippingService,

                TotalPrice = o.TotalPrice,
                TotalPriceCurrency = o.TotalPriceCurrency,
                Items = new List <DTOOrderItem>
                {
                    new DTOOrderItem
                    {
                        OrderId = oi.OrderId,
                        ItemOrderId = oi.ItemOrderIdentifier,
                        SourceItemOrderId = oi.SourceItemOrderIdentifier,

                        Weight = l.Weight ?? 0,
                        PackageLength = l.PackageLength,
                        PackageWidth = l.PackageWidth,
                        PackageHeight = l.PackageHeight,

                        Quantity = oi.QuantityOrdered,
                        ItemPriceCurrency = o.TotalPriceCurrency,             //NOTE: oi.ItemPriceCurrency is emtpy!
                        ItemPrice = oi.ItemPrice,

                        StyleItemId = l.StyleItemId,
                        StyleEntityId = l.StyleId,
                        StyleId = l.StyleString,
                        Size = l.Size,
                        ASIN = l.ASIN,
                        ParentASIN = l.ParentASIN
                    }
                },
            }).ToList();

            var orders    = query.ToList();
            var mainOrder = orders.FirstOrDefault();

            if (mainOrder != null)
            {
                var byItems = query.OrderByDescending(q => q.Items.First().Quantity)
                              .ToList()
                              .Select(q => q.Items.First())
                              .ToList();

                if (byItems.Any())
                {
                    var weight = byItems.All(i => i.Weight > 0) ? byItems.Sum(i => i.Weight * i.Quantity) : 0;
                    if (weight > 0)
                    {
                        weight = weightService == null ? weight : weightService.AdjustWeight(weight, byItems.Sum(i => i.Quantity));
                    }
                    mainOrder.WeightLb = weight > 16 ? (int)weight / 16 : 0;
                    mainOrder.WeightOz = weight % 16;

                    if (weightService != null)
                    {
                        var packageSize = weightService.ComposePackageSize(byItems);
                        mainOrder.PackageLength = packageSize.PackageLength;
                        mainOrder.PackageWidth  = packageSize.PackageWidth;
                        mainOrder.PackageHeight = packageSize.PackageHeight;
                    }

                    mainOrder.Items = byItems;
                }

                var labels = unitOfWork.OrderShippingInfos.GetAllAsDto()
                             .Where(l => l.OrderId == mainOrder.OrderEntityId &&
                                    !String.IsNullOrEmpty(l.LabelPath) &&
                                    !l.LabelCanceled)
                             .ToList();

                labels.AddRange(unitOfWork.MailLabelInfos.GetAllAsDto()
                                .Where(l => l.OrderId == mainOrder.OrderEntityId &&
                                       !l.LabelCanceled));

                mainOrder.Labels      = labels;
                mainOrder.OrderStatus = orders.Any(o => o.OrderStatus == OrderStatusEnumEx.Unshipped) ? OrderStatusEnumEx.Unshipped : mainOrder.OrderStatus;
            }
            return(mainOrder);
        }
        public static OrderHistoryViewModel GetByOrderId(IUnitOfWork db,
                                                         ILogService log,
                                                         IWeightService weightService,
                                                         string orderId)
        {
            DTOOrder order = null;

            if (!String.IsNullOrEmpty(orderId))
            {
                orderId = orderId.RemoveWhitespaces();
                var orderNumber = OrderHelper.RemoveOrderNumberFormat(orderId);
                var filter      = new OrderSearchFilter()
                {
                    EqualOrderNumber = orderNumber,
                    IncludeMailInfos = true,
                    IncludeNotify    = false,

                    UnmaskReferenceStyles = false,
                };

                order = db.ItemOrderMappings
                        .GetFilteredOrdersWithItems(weightService, filter)
                        .FirstOrDefault();
            }

            if (order == null)
            {
                return(null);
            }
            else
            {
                var anotherBuyerOrders = new List <OrderLinkViewModel>();
                if (!String.IsNullOrEmpty(order.BuyerEmail))
                {
                    anotherBuyerOrders = db.Orders.GetAll().Where(o => o.BuyerEmail == order.BuyerEmail)
                                         .ToList()
                                         .Where(o => o.Id != order.Id)
                                         .OrderByDescending(o => o.OrderDate)
                                         .Select(o => new OrderLinkViewModel()
                    {
                        OrderId       = o.Id,
                        OrderNumber   = o.AmazonIdentifier,
                        OrderDate     = o.OrderDate,
                        OrderStatus   = o.OrderStatus,
                        Market        = o.Market,
                        MarketplaceId = o.MarketplaceId
                    })
                                         .ToList();
                }

                var comments = db.OrderComments.GetByOrderIdDto(order.Id).ToList();

                var emails = db.Emails.GetAllWithOrder(new EmailSearchFilter()
                {
                    OrderId = orderId
                }).ToList();

                var returnRequests = db.ReturnRequests.GetAll()
                                     .OrderByDescending(r => r.CreateDate)
                                     .Select(r => new ReturnRequestDTO()
                {
                    OrderNumber      = r.OrderNumber,
                    ReceiveDate      = r.ReceiveDate,
                    ItemName         = r.ItemName,
                    CustomerComments = r.CustomerComments,
                    Details          = r.Details,
                    CreateDate       = r.CreateDate,
                    Reason           = r.Reason
                })
                                     .Where(r => r.OrderNumber == order.OrderId)
                                     .ToList();

                var refundRequests = RefundViewModel.GetByOrderId(db, order.OrderId);

                var labels = order.ShippingInfos
                             .Where(i => !String.IsNullOrEmpty(i.LabelPath)
                                    //|| i.LabelPurchaseResult != null //NOTE: in case when bag system shows user issue (keeped twice shippings with labels)
                                    )
                             .ToList();
                labels.AddRange(order.MailInfos);


                var address = order.GetAddressDto();

                var changes = db.OrderChangeHistories.GetByOrderIdDto(order.Id)
                              .ToList()
                              .OrderByDescending(ch => ch.ChangeDate)
                              .Select(ch => new OrderChangeViewModel(ch, emails))
                              .Where(ch => ch.ChangeType != OrderChangeTypes.None) //NOTE: Skipped empty
                              .ToList();

                changes.Add(OrderChangeViewModel.BuildCreateOrderChange(order));
                changes.AddRange(comments.Select(c => new OrderChangeViewModel(c)).ToList());
                changes.AddRange(emails.Select(e => new OrderChangeViewModel(e)).ToList());
                changes.AddRange(labels.SelectMany(l => OrderChangeViewModel.BuildChanges(l)).ToList());
                changes.AddRange(refundRequests.Select(r => new OrderChangeViewModel(r)).ToList());
                changes.AddRange(returnRequests.Select(r => new OrderChangeViewModel(r)).ToList());

                return(new OrderHistoryViewModel
                {
                    //Notes =  string.Format("{0} {1}", order.OrderId, itemsNotes),
                    OrderID = order.OrderId,
                    OrderEntityId = order.Id,
                    OrderDate = order.OrderDate,
                    Market = (MarketType)order.Market,
                    MarketplaceId = order.MarketplaceId,

                    WeightLb = (int)Math.Floor(order.WeightD / 16),
                    WeightOz = order.WeightD % 16,
                    TotalPrice = order.TotalPrice,
                    PriceCurrency = PriceHelper.FormatCurrency(order.TotalPriceCurrency),

                    Items = order.Items.Select(i => new OrderItemViewModel(i, false, false)).ToList(),
                    Changes = changes.OrderByDescending(c => c.ChangeDate).ToList(),

                    AnotherOrders = anotherBuyerOrders,

                    ToAddress = new AddressViewModel(address),
                });
            }
        }
Exemplo n.º 30
0
        public IOrderSynchronizer GetForMarket(IMarketApi api,
                                               ILogService log,
                                               CompanyDTO company,
                                               ISettingsService settings,
                                               ISyncInformer syncInfo,
                                               IList <IShipmentApi> rateProviders,
                                               IQuantityManager quantityManager,
                                               IEmailService emailService,
                                               IOrderValidatorService validatorService,
                                               IOrderHistoryService orderHistoryService,
                                               ICacheService cacheService,
                                               ISystemActionService systemAction,
                                               ICompanyAddressService companyAddress,
                                               ITime time,
                                               IWeightService weightService,
                                               ISystemMessageService messageService)
        {
            IOrderSynchronizer synchronizer = null;

            switch (api.Market)
            {
            case MarketType.Amazon:
            case MarketType.AmazonEU:
            case MarketType.AmazonAU:
                synchronizer = new AmazonOrdersSynchronizer(log,
                                                            api,
                                                            company,
                                                            settings,
                                                            syncInfo,
                                                            rateProviders,
                                                            quantityManager,
                                                            emailService,
                                                            validatorService,
                                                            orderHistoryService,
                                                            cacheService,
                                                            systemAction,
                                                            companyAddress,
                                                            time,
                                                            weightService,
                                                            messageService);
                break;

            case MarketType.eBay:
                synchronizer = new EBayOrdersSynchronizer(log,
                                                          api,
                                                          company,
                                                          settings,
                                                          syncInfo,
                                                          rateProviders,
                                                          quantityManager,
                                                          emailService,
                                                          validatorService,
                                                          orderHistoryService,
                                                          cacheService,
                                                          systemAction,
                                                          companyAddress,
                                                          time,
                                                          weightService,
                                                          messageService);
                break;

            case MarketType.Magento:
                synchronizer = new MagentoOrdersSynchronizer(log,
                                                             api,
                                                             company,
                                                             settings,
                                                             syncInfo,
                                                             rateProviders,
                                                             quantityManager,
                                                             emailService,
                                                             validatorService,
                                                             orderHistoryService,
                                                             cacheService,
                                                             systemAction,
                                                             companyAddress,
                                                             time,
                                                             weightService,
                                                             messageService);
                break;

            case MarketType.Groupon:
                synchronizer = new GrouponOrdersSynchronizer(log,
                                                             api,
                                                             company,
                                                             settings,
                                                             syncInfo,
                                                             rateProviders,
                                                             quantityManager,
                                                             emailService,
                                                             validatorService,
                                                             orderHistoryService,
                                                             cacheService,
                                                             systemAction,
                                                             companyAddress,
                                                             time,
                                                             weightService,
                                                             messageService);
                break;

            case MarketType.Shopify:
                synchronizer = new ShopifyOrdersSynchronizer(log,
                                                             api,
                                                             company,
                                                             settings,
                                                             syncInfo,
                                                             rateProviders,
                                                             quantityManager,
                                                             emailService,
                                                             validatorService,
                                                             orderHistoryService,
                                                             cacheService,
                                                             systemAction,
                                                             companyAddress,
                                                             time,
                                                             weightService,
                                                             messageService);
                break;

            case MarketType.WooCommerce:
                synchronizer = new WooCommerceOrdersSynchronizer(log,
                                                                 api,
                                                                 company,
                                                                 settings,
                                                                 syncInfo,
                                                                 rateProviders,
                                                                 quantityManager,
                                                                 emailService,
                                                                 validatorService,
                                                                 orderHistoryService,
                                                                 cacheService,
                                                                 systemAction,
                                                                 companyAddress,
                                                                 time,
                                                                 weightService,
                                                                 messageService);
                break;

            case MarketType.Walmart:
            case MarketType.WalmartCA:
                synchronizer = new WalmartOrdersSynchronizer(log,
                                                             api,
                                                             company,
                                                             settings,
                                                             syncInfo,
                                                             rateProviders,
                                                             quantityManager,
                                                             emailService,
                                                             validatorService,
                                                             orderHistoryService,
                                                             cacheService,
                                                             systemAction,
                                                             companyAddress,
                                                             time,
                                                             weightService,
                                                             messageService);
                break;

            case MarketType.Jet:
                synchronizer = new JetOrdersSynchronizer(log,
                                                         api,
                                                         company,
                                                         settings,
                                                         syncInfo,
                                                         rateProviders,
                                                         quantityManager,
                                                         emailService,
                                                         validatorService,
                                                         orderHistoryService,
                                                         cacheService,
                                                         systemAction,
                                                         companyAddress,
                                                         time,
                                                         weightService,
                                                         messageService);
                break;

            case MarketType.DropShipper:
                synchronizer = new DSOrdersSynchronizer(log,
                                                        api,
                                                        company,
                                                        settings,
                                                        syncInfo,
                                                        rateProviders,
                                                        quantityManager,
                                                        emailService,
                                                        validatorService,
                                                        orderHistoryService,
                                                        cacheService,
                                                        systemAction,
                                                        companyAddress,
                                                        time,
                                                        weightService,
                                                        messageService);
                break;

            case MarketType.OverStock:
                synchronizer = new SupplierOasisOrdersSynchronizer(log,
                                                                   api,
                                                                   company,
                                                                   settings,
                                                                   syncInfo,
                                                                   rateProviders,
                                                                   quantityManager,
                                                                   emailService,
                                                                   validatorService,
                                                                   orderHistoryService,
                                                                   cacheService,
                                                                   systemAction,
                                                                   companyAddress,
                                                                   time,
                                                                   weightService,
                                                                   messageService);
                break;

            case MarketType.OfflineOrders:
                synchronizer = new UserOrdersSynchronizer(log,
                                                          api,
                                                          company,
                                                          settings,
                                                          syncInfo,
                                                          rateProviders,
                                                          quantityManager,
                                                          emailService,
                                                          validatorService,
                                                          orderHistoryService,
                                                          cacheService,
                                                          systemAction,
                                                          companyAddress,
                                                          time,
                                                          weightService,
                                                          messageService);
                break;

            default:
                throw new NotImplementedException("MarketType not supported=" + api.Market.ToString());
                break;
            }

            return(synchronizer);
        }