Esempio n. 1
0
        /// <summary>
        /// Gets a language
        /// </summary>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Language</returns>
        public static Language GetLanguageById(int languageId)
        {
            if (languageId == 0)
            {
                return(null);
            }

            string key  = string.Format(LANGUAGES_BY_ID_KEY, languageId);
            object obj2 = NopStaticCache.Get(key);

            if (LanguageManager.CacheEnabled && (obj2 != null))
            {
                return((Language)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from l in context.Languages
                          where l.LanguageId == languageId
                          select l;
            var language = query.SingleOrDefault();

            if (LanguageManager.CacheEnabled)
            {
                NopStaticCache.Max(key, language);
            }
            return(language);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a currency
        /// </summary>
        /// <param name="currencyId">Currency identifier</param>
        /// <returns>Currency</returns>
        public static Currency GetCurrencyById(int currencyId)
        {
            if (currencyId == 0)
            {
                return(null);
            }

            string key  = string.Format(CURRENCIES_BY_ID_KEY, currencyId);
            object obj2 = NopStaticCache.Get(key);

            if (CurrencyManager.CacheEnabled && (obj2 != null))
            {
                return((Currency)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from c in context.Currencies
                          where c.CurrencyId == currencyId
                          select c;
            var currency = query.SingleOrDefault();

            if (CurrencyManager.CacheEnabled)
            {
                NopStaticCache.Max(key, currency);
            }
            return(currency);
        }
Esempio n. 3
0
        private static Dictionary <Guid, OnlineUserInfo> GetRegisteredUserList()
        {
            string key = "Nop.OnlineUserList.Registered";
            Dictionary <Guid, OnlineUserInfo> obj2 = NopStaticCache.Get(key) as Dictionary <Guid, OnlineUserInfo>;

            if (obj2 != null)
            {
                return(obj2);
            }
            else
            {
                obj2 = new Dictionary <Guid, OnlineUserInfo>();
                NopStaticCache.Max(key, obj2);
            }

            return(obj2);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets all settings
        /// </summary>
        /// <returns>Setting collection</returns>
        public static Dictionary <string, Setting> GetAllSettings()
        {
            string key  = SETTINGS_ALL_KEY;
            object obj2 = NopStaticCache.Get(key);

            if (SettingManager.CacheEnabled && (obj2 != null))
            {
                return((Dictionary <string, Setting>)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from s in context.Settings
                          orderby s.Name
                          select s;
            var settings = query.ToDictionary(s => s.Name.ToLowerInvariant());

            if (SettingManager.CacheEnabled)
            {
                NopStaticCache.Max(key, settings);
            }
            return(settings);
        }
        /// <summary>
        /// Gets all locale string resources by language identifier
        /// </summary>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Locale string resource collection</returns>
        public static Dictionary <string, LocaleStringResource> GetAllResourcesByLanguageId(int languageId)
        {
            string key  = string.Format(LOCALSTRINGRESOURCES_ALL_KEY, languageId);
            object obj2 = NopStaticCache.Get(key);

            if (LocaleStringResourceManager.CacheEnabled && (obj2 != null))
            {
                return((Dictionary <string, LocaleStringResource>)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from l in context.LocaleStringResources
                          orderby l.ResourceName
                          where l.LanguageId == languageId
                          select l;
            var localeStringResourceDictionary = query.ToDictionary(s => s.ResourceName.ToLowerInvariant());

            if (LocaleStringResourceManager.CacheEnabled)
            {
                NopStaticCache.Max(key, localeStringResourceDictionary);
            }
            return(localeStringResourceDictionary);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets all languages
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Language collection</returns>
        public static List <Language> GetAllLanguages(bool showHidden)
        {
            string key  = string.Format(LANGUAGES_ALL_KEY, showHidden);
            object obj2 = NopStaticCache.Get(key);

            if (LanguageManager.CacheEnabled && (obj2 != null))
            {
                return((List <Language>)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from l in context.Languages
                          orderby l.DisplayOrder
                          where showHidden || l.Published
                          select l;
            var languages = query.ToList();

            if (LanguageManager.CacheEnabled)
            {
                NopStaticCache.Max(key, languages);
            }
            return(languages);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets all currencies
        /// </summary>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Currency collection</returns>
        public static List <Currency> GetAllCurrencies(bool showHidden)
        {
            string key  = string.Format(CURRENCIES_ALL_KEY, showHidden);
            object obj2 = NopStaticCache.Get(key);

            if (CurrencyManager.CacheEnabled && (obj2 != null))
            {
                return((List <Currency>)obj2);
            }

            var context = ObjectContextHelper.CurrentObjectContext;
            var query   = from c in context.Currencies
                          orderby c.DisplayOrder
                          where showHidden || c.Published
                          select c;
            var currencies = query.ToList();

            if (CurrencyManager.CacheEnabled)
            {
                NopStaticCache.Max(key, currencies);
            }
            return(currencies);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a tax rate
        /// </summary>
        /// <param name="province">province</param>
        /// <param name="userID">UserID</param>
        /// <param name="password">Password</param>
        /// <param name="error">Error</param>
        /// <returns>Tax rate</returns>
        public decimal GetTaxRateCanada(string province, string userID,
                                        string password, ref string error)
        {
            decimal result = decimal.Zero;
            string  key    = string.Format(TAXRATECANADA_KEY, province);
            object  obj2   = NopStaticCache.Get(key);

            if (StrikeIronTaxProvider.CacheEnabled && (obj2 != null))
            {
                return((decimal)obj2);
            }

            try
            {
                NopSolutions.NopCommerce.Tax.TaxDataBasic.TaxDataBasic taxService = new NopSolutions.NopCommerce.Tax.TaxDataBasic.TaxDataBasic();
                taxService.LicenseInfoValue = new LicenseInfo();
                taxService.LicenseInfoValue.RegisteredUser          = new RegisteredUser();
                taxService.LicenseInfoValue.RegisteredUser.UserID   = userID;
                taxService.LicenseInfoValue.RegisteredUser.Password = password;

                // The GetTaxRateCanada operation can now be called.  The output type for this operation is SIWSOutputOfTaxRateCanadaData.
                // Note that for simplicity, there is no error handling in this sample project.  In a production environment, any
                // web service call should be encapsulated in a try-catch block.
                //
                var wsOutput = taxService.GetTaxRateCanada(province);

                // The output objects of this StrikeIron web service contains two sections: ServiceStatus, which stores data
                // indicating the success/failure status of the the web service request; and ServiceResult, which contains the
                // actual data returne as a result of the request.
                //
                // ServiceStatus contains two elements - StatusNbr: a numeric status code, and StatusDescription: a string
                // describing the status of the output object.  As a standard, you can apply the following assumptions for the value of
                // StatusNbr:
                //   200-299: Successful web service call (data found, etc...)
                //   300-399: Nonfatal error (No data found, etc...)
                //   400-499: Error due to invalid input
                //   500+: Unexpected internal error; contact [email protected]
                //
                if ((wsOutput.ServiceStatus.StatusNbr >= 200) && (wsOutput.ServiceStatus.StatusNbr < 300))
                {
                    //Successfully called SalesTax service...
                    var sb = new StringBuilder();
                    sb.AppendLine("Abbreviation: " + wsOutput.ServiceResult.Abbreviation);
                    sb.AppendLine("GST: " + wsOutput.ServiceResult.GST.ToString());
                    sb.AppendLine("province: " + wsOutput.ServiceResult.Province);
                    sb.AppendLine("PST: " + wsOutput.ServiceResult.PST.ToString());
                    sb.AppendLine("tax_shipping_handling: " + wsOutput.ServiceResult.TaxShippingHandling);
                    sb.AppendLine("total: " + wsOutput.ServiceResult.Total.ToString());
                    string debug = sb.ToString();
                    result = Convert.ToDecimal(wsOutput.ServiceResult.Total);
                }
                else
                {
                    // StrikeIron does not return SoapFault for invalid data when it cannot find a zipcode.
                    error = String.Format("[{0}] - {1}", wsOutput.ServiceStatus.StatusNbr.ToString(), wsOutput.ServiceStatus.StatusDescription);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (StrikeIronTaxProvider.CacheEnabled)
            {
                NopStaticCache.Max(key, result);
            }

            return(result);
        }