Esempio n. 1
0
        /// <summary>
        /// Fetches all tips by the specified language from database.
        /// </summary>
        /// <returns>Array of tips.</returns>
        public static TipPopup[] FetchTipsByLanguage(int languageID)
        {
            string cacheKey = String.Format("TipPopup_FetchTipsByLanguage_{0}", languageID);
            if (HttpContext.Current != null && HttpContext.Current.Cache[cacheKey] != null)
            {
                return HttpContext.Current.Cache[cacheKey] as TipPopup[];
            }

            List<TipPopup> lstTips = new List<TipPopup>();

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn,
                                            "FetchTipsForLanguage", languageID);

                while (reader.Read())
                {
                    TipPopup tip = new TipPopup
                    {
                        _id = (int)reader["ID"],
                        LanguageID = (int)reader["LanguageId"],
                        Content = (string)reader["ContentText"],
                        Key = (string)reader["NameKey"],
                        Title = (string)reader["TitleText"],
                        ShowPageName = (string)reader["ShowPageName"],
                        DaysCountTrigger = (int)reader["DaysCountTrigger"],
                        LoginCountTrigger = (int)reader["LoginCountTrigger"],
                        MinCreditsTrigger = (int)reader["MinCreditsTrigger"],
                        NoSpendingDaysTrigger = (int)reader["NoSpendingDaysTrigger"],
                        ShowTimes = (int)reader["ShowTimes"],
                        IsMatchmakerTip = (bool)reader["IsMatchmakerTip"]
                    };
                    lstTips.Add(tip);
                }
            }
            var arr = lstTips.ToArray();
            if (HttpContext.Current != null)
            {
                HttpContext.Current.Cache.Insert(cacheKey, arr, null, DateTime.Now.AddMinutes(30),
                    Cache.NoSlidingExpiration, CacheItemPriority.NotRemovable, null);
            }
            return arr;
        }
Esempio n. 2
0
        /// <summary>
        /// Fetches tip by its id from database.
        /// </summary>
        /// <returns>Popup Tip object.</returns>
        public static TipPopup Fetch(int id)
        {
            TipPopup tip = null;

            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn, "FetchTip", id);

                if (reader.Read())
                {
                    tip = new TipPopup
                    {
                        _id = (int)reader["ID"],
                        LanguageID = (int)reader["LanguageId"],
                        Content = (string)reader["ContentText"],
                        Key = (string)reader["NameKey"],
                        Title = (string)reader["TitleText"],
                        ShowPageName = (string)reader["ShowPageName"],
                        DaysCountTrigger = (int)reader["DaysCountTrigger"],
                        LoginCountTrigger = (int)reader["LoginCountTrigger"],
                        MinCreditsTrigger = (int)reader["MinCreditsTrigger"],
                        NoSpendingDaysTrigger = (int)reader["NoSpendingDaysTrigger"],
                        ShowTimes = (int)reader["ShowTimes"],
                        IsMatchmakerTip = (bool)reader["IsMatchmakerTip"]
                    };
                }
            }
            return tip;
        }