public void Init()
        {
            using (var db = _dbFactory.GetRWDb())
            {
                var allSettings  = db.Settings.GetAll().ToList();
                var marketplaces = new MarketplaceKeeper(_dbFactory, false);
                marketplaces.Init();

                _marketSettings = new List <MarketplaceInfo>();
                foreach (var marketplace in marketplaces.GetAll())
                {
                    var market        = (MarketType)marketplace.Market;
                    var marketplaceId = marketplace.MarketplaceId;

                    var info = new MarketplaceInfo();
                    info.Market        = market;
                    info.MarketplaceId = marketplaceId;

                    info.OrderSyncDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                           MarketKey(KeyOrdersSyncDate, market, marketplaceId));
                    info.OrdersFulfillmentDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                                   MarketKey(KeyOrdersFulfillmentDate, market, marketplaceId));
                    info.OrderCountOnMarket = SettingsHelper.GetIntSetting(allSettings,
                                                                           MarketKey(KeyOrdersCountOnAmazon, market, marketplaceId));
                    info.OrderCountInDb = SettingsHelper.GetIntSetting(allSettings,
                                                                       MarketKey(KeyOrdersCountInDB, market, marketplaceId));

                    info.ListingsSyncDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                              MarketKey(KeyListingsSendDate, market, marketplaceId));
                    info.ListingsSyncInProgress = SettingsHelper.GetBoolSetting(allSettings,
                                                                                MarketKey(KeyListingsSyncInProgress, market, marketplaceId));
                    info.ListingsManualSyncRequest = SettingsHelper.GetBoolSetting(allSettings,
                                                                                   MarketKey(KeyListingsManualSyncRequest, market, marketplaceId));

                    info.ListingsQuantityToAmazonSyncDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                                              MarketKey(KeyListingsQuantityToAmazonSyncDate, market, marketplaceId));
                    info.ListingsPriceSyncDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                                   MarketKey(KeyListingsPriceSyncDate, market, marketplaceId));

                    info.RankSyncDate = SettingsHelper.GetDateTimeSetting(allSettings,
                                                                          MarketKey(KeyRankSyncDate, market, marketplaceId));
                    info.ListingQtyAlert = SettingsHelper.GetIntSetting(allSettings,
                                                                        MarketKey(KeyListingsQtyAlert, market, marketplaceId));
                    info.ListingPriceAlert = SettingsHelper.GetIntSetting(allSettings,
                                                                          MarketKey(KeyListingsPriceAlert, market, marketplaceId));

                    _marketSettings.Add(info);
                }

                //Cache
                _cacheUpdateDate       = SettingsHelper.GetDateTimeSetting(allSettings, KeyCacheUpdateDate);
                _cacheUpdateInProgress = SettingsHelper.GetBoolSetting(allSettings, KeyCacheUpdateInProgress);
            }
        }
        public MarketplaceViewModel(MarketplaceInfo marketplace, ISettingsService settings)
        {
            Market        = marketplace.Market;
            MarketplaceId = marketplace.MarketplaceId;

            ListingQtyAlert    = marketplace.ListingQtyAlert;
            ListingPriceAlert  = marketplace.ListingPriceAlert;
            OrderCountOnMarket = marketplace.OrderCountOnMarket;
            OrderCountInDb     = marketplace.OrderCountInDb;

            OrderSyncDate                    = marketplace.OrderSyncDate;
            OrdersFulfillmentDate            = marketplace.OrdersFulfillmentDate;
            ListingsSyncDate                 = marketplace.ListingsSyncDate;
            ListingsPriceSyncDate            = marketplace.ListingsPriceSyncDate;
            ListingsQuantityToAmazonSyncDate = marketplace.ListingsQuantityToAmazonSyncDate;

            OrderSyncInterval            = settings.GetOrdersSyncInterval(marketplace.Market, marketplace.MarketplaceId);
            OrdersFulfillmentInterval    = settings.OrdersFulfillmentInterval;
            ListingsSyncInterval         = settings.ListingsSyncInterval;
            ListingsPriceSyncInterval    = settings.ListingsPriceSyncInterval;
            ListingsQuantitySyncInterval = settings.ListingsQuantitySyncInterval;
        }