Example #1
0
        public static void UpdatePopupTips(UserSession userSession)
        {
            if (userSession == null) return;

            var langTips = TipPopup.FetchTipsByLanguage(PageBase.GetLanguageId())
                    .Where(p => p.Content.IsNotNullOrEmpty() && p.Title.IsNotNullOrEmpty()).ToList();
            langTips.ForEach(p => p.ShowPageName = p.ShowPageName
                                                    .Replace("https://", "")
                                                    .Replace("https://", "")
                                                    .Replace("lovehitch.com/", "")
                                                    .ToLower());
            userSession.ProfileTipsStatus = UserTipStatus.FetchTipStatusForUsername(userSession.Username).ToList();
            if (langTips != null && langTips.Count > 0)
            {
                var userTipIds = userSession.ProfileTipsStatus == null
                                    ? new List<int>()
                                    : userSession.ProfileTipsStatus.Select(c => c.TipId).ToList();
                var langTipIds = langTips.Select(c => c.ID).ToList();

                foreach (int id in langTipIds)
                {
                    if (!userTipIds.Contains(id))
                    {
                        UserTipStatus newTip = new UserTipStatus
                        {
                            IsBlocked = false,
                            LastViewedDate = DateTime.Now.AddMonths(-1),
                            TipId = id,
                            Username = userSession.Username,
                            ViewedTimes = 0
                        };
                        newTip.Save();
                        userSession.ProfileTipsStatus.Add(newTip);
                    }
                }
                foreach (TipPopup tip in langTips)
                {
                    var userTipStatus = userSession.ProfileTipsStatus.FirstOrDefault(c => c.TipId == tip.ID);
                    bool viewCondition = userTipStatus != null && !userTipStatus.IsBlocked
                                        && tip.ShowTimes > userTipStatus.ViewedTimes
                                        &&
                                        (tip.DaysCountTrigger <= (DateTime.Now - userTipStatus.LastViewedDate).Days
                                        || tip.LoginCountTrigger <= (DateTime.Now - userSession.LastOnline).Days
                        //|| tip.NoSpendingDaysTrigger <= userSession.Credits
                                        );
                    if (viewCondition)
                    {
                        string[] pages = tip.ShowPageName.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string page in pages)
                        {
                            if (userSession.TipsToPageViewDic.ContainsKey(page))
                            {
                                userSession.TipsToPageViewDic[page].Add(tip);
                            }
                            else
                            {
                                userSession.TipsToPageViewDic.Add(page, new List<TipPopup> { tip });
                            }
                        }
                    }
                }
            }
            var tipsStatuss = userSession.ProfileTipsStatus;
            var orderedTipsDic = new Dictionary<string, List<TipPopup>>();
            foreach (string key in userSession.TipsToPageViewDic.Keys)
            {
                orderedTipsDic.Add(key,
                    userSession.TipsToPageViewDic[key].
                    OrderBy(c => tipsStatuss.First(s => s.TipId == c.ID).LastViewedDate).
                    ToList());
            }
            userSession.TipsToPageViewDic = orderedTipsDic;
        }
Example #2
0
        public static UserTipStatus[] FetchTipStatusForUsername(string username)
        {
            List<UserTipStatus> lstTips = new List<UserTipStatus>();

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

                while (reader.Read())
                {
                    UserTipStatus status = new UserTipStatus
                    {
                        TipId = (int)reader["TipId"],
                        ViewedTimes = (int)reader["ViewedTimes"],
                        IsBlocked = (bool)reader["IsBlocked"],
                        LastViewedDate = (DateTime)reader["LastViewedDate"]
                    };
                    lstTips.Add(status);
                }
            }
            return lstTips.ToArray();
        }