示例#1
0
    protected void LoadAds()
    {
        Form.Action = Request.RawUrl;

        List <PtcAdvert> AvailableAdList;

        CreatedCustomCategories = new List <int>();

        Member user = null;

        if (Member.IsLogged)
        {
            user = Member.Current;
            int temporaryAdvertId = 0;
            if (AppSettings.PtcAdverts.BlockPtcAdvertsAfterMissingPointer &&
                Request.Params.Get("__EVENTARGUMENT5") != null && Int32.TryParse(Request.Params.Get("__EVENTARGUMENT5"), out temporaryAdvertId))
            {
                // User missed the anti-robot button 3 times
                // Blocking this particualr ad for him
                List <int> av = user.AdsViewed;
                av.Add(temporaryAdvertId); // Blocking = adding to watched
                user.AdsViewed = av;
                user.Save();

                NotificationManager.RefreshWithMember(NotificationType.NewAds, user);
            }

            AvailableAdList = PtcAdvert.GetActiveAdsForUser(user);
        }
        else
        {
            AvailableAdList = PtcAdvert.GetAllActiveAds();
        }

        if (AvailableAdList.Count == 0)
        {
            MenuMultiView.Visible     = false;
            NoPTCpanelWrapper.Visible = true;
            NoPTCpanel.Visible        = true;
            NoPTCpanel.Text           = U6003.NOPTC;
        }
        else
        {
            if (!string.IsNullOrWhiteSpace(Request.Params.Get("__EVENTARGUMENT")))
            {
                string agrument = Request.Params.Get("__EVENTARGUMENT");
                if (PTCSercurityManager.IsPTCAdvertFound(agrument, AvailableAdList))
                {
                    PTCSercurityManager.Release();
                }
            }

            //Sort by favorite?
            if (Member.IsLogged)
            {
                if (SortBy1.SelectedValue == "Favorite")
                {
                    var favorites = FavoriteAd.GetUserFavorites(Member.CurrentId, FavoriteAdType.PTC);
                    AvailableAdList = AvailableAdList.OrderByDescending(i => favorites.Contains(i.Id)).ToList();
                }
                else if (SortBy1.SelectedValue == "Voted")
                {
                    var favorites = FavoriteAd.GetUserFavorites(Member.CurrentId, FavoriteAdType.PTC);
                    AvailableAdList = AvailableAdList.OrderByDescending(i => i.CaptchaYesAnswers - i.CaptchaNoAnswers).ToList();
                }
            }

            //Display proper ads to the Member
            try
            {
                //Lets get the proper ads to the member
                foreach (PtcAdvert Ad in AvailableAdList)
                {
                    bool IsSearch = !string.IsNullOrWhiteSpace(SearchTextBox.Text);

                    if (!IsSearch || (IsSearch && IsSearchRequirementsMeet(Ad, SearchTextBox.Text)))
                    {
                        if (AppSettings.PtcAdverts.PTCCategoryPolicy == AppSettings.PTCCategoryPolicy.Custom)
                        {
                            //Display Custom Categories
                            CustomCategoriesPlaceHolder.Visible = true;
                            if (!CreatedCustomCategories.Contains(Ad.CategoryId))
                            {
                                CreatedCustomCategories.Add(Ad.CategoryId);
                            }

                            CustomCategoriesPlaceHolder.Controls.Add(GetAdHTML(Ad, user));
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(Ad.Description) && Ad.IsStarredAd == false)
                            {
                                SmallAdsLiteral.Controls.Add(GetAdHTML(Ad, user, ""));
                            }
                            else
                            {
                                AdsLiteral.Controls.Add(GetAdHTML(Ad, user, ""));
                            }
                        }
                    }
                }
                if (AppSettings.PtcAdverts.PTCCategoryPolicy == AppSettings.PTCCategoryPolicy.Custom)
                {
                    foreach (var categoryId in CreatedCustomCategories)
                    {
                        LoadCustomCategoryButton(categoryId);
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
示例#2
0
    private static int RefreshAndGetValue(NotificationType type, Member user = null)
    {
        if (!Member.IsLogged)
        {
            return(0);
        }

        if (user == null)
        {
            user = Member.CurrentInCache;
        }

        switch (type)
        {
        case NotificationType.NewAds:

            List <PtcAdvert> AvailableAdList = PtcAdvert.GetActiveAdsForUser(user);
            int newAdsCounter = 0;

            foreach (PtcAdvert Ad in AvailableAdList)
            {
                if (!user.AdsViewed.Contains(Ad.Id))
                {
                    newAdsCounter++;
                }
            }
            return(newAdsCounter);

        case NotificationType.NewMessages:
            return(ConversationMessage.GetNumberOfUnreadMessages(Member.CurrentId));

        case NotificationType.NewDirectReferrals:

            using (var bridge = ParserPool.Acquire(Database.Client))
            {
                return((int)bridge.Instance.ExecuteRawCommandScalar("SELECT COUNT (*) FROM Users WHERE IsSpotted = 0 AND ReferrerId = "
                                                                    + Member.CurrentId));
            }

        case NotificationType.NewAchievements:

            return(user.UnspottedAchievements);

        case NotificationType.NewCPAOffers:
            //CPAOFfers
            //User is already loaded
            var OM = new OffersManager(user);
            return(OM.AllActiveOffersForMember.Count);

        case NotificationType.UnreadSupportTickets:

            return((int)TableHelper.SelectScalar(String.Format("SELECT COUNT(*) FROM SupportTickets WHERE IsRead = 0 AND FromUsername = '******'",
                                                               Member.CurrentName)));


        case NotificationType.NewAdPacksAds:

            List <AdPacksAdvert> AdPacksAdList = AdPackManager.GetAdPacksAdvertsForUsers(user.Membership.AdPackDailyRequiredClicks);
            int numberofAdsViewed = user.RSAPTCAdsViewed.Count();

            int adsRequiredToWatch = user.Membership.AdPackDailyRequiredClicks - numberofAdsViewed;

            if (adsRequiredToWatch <= 0)
            {
                return(0);
            }

            if (adsRequiredToWatch > AdPacksAdList.Count)
            {
                int adCount = 0;
                foreach (AdPacksAdvert ad in AdPacksAdList)
                {
                    if (!user.RSAPTCAdsViewed.Contains(ad.Id))
                    {
                        adCount++;
                    }
                }
                return(adCount);
            }
            return(adsRequiredToWatch);

        case NotificationType.UnassignedMatrixMembers:
            return(user.GetUnassignedMatrixMembersCount());

        case NotificationType.PendingRepresentativePaymentRequest:
            return(ConversationMessage.GetPendingRequestForRepresentativeCount(user.Id));

        default:
            return(0);
        }
    }