Example #1
0
    protected void ChangeCampaignButton_Click(object sender, EventArgs e)
    {
        if (AppSettings.RevShare.AdPack.EnableAdvertChange)
        {
            for (int i = 0; i < SurfAdsStatsGridView.Rows.Count; i++)
            {
                GridViewRow row       = SurfAdsStatsGridView.Rows[i];
                bool        isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked;

                if (isChecked)
                {
                    int    adpackId = Convert.ToInt32(row.Cells[1].Text);
                    AdPack adpack   = new AdPack(adpackId);
                    adpack.AdPacksAdvertId = Convert.ToInt32(ddlCampaigns2.SelectedValue);

                    if (!AdPackManager.HasConstantBanner(adpack.AdPacksAdvertId))
                    {
                        adpack.TotalConstantBannerImpressions = adpack.ConstantBannerImpressionsBought;
                    }
                    if (!AdPackManager.HasNormalBanner(adpack.AdPacksAdvertId))
                    {
                        adpack.TotalNormalBannerImpressions = adpack.NormalBannerImpressionsBought;
                    }

                    adpack.Save();
                }
            }
            SurfAdsStatsGridView.DataBind();
        }
    }
Example #2
0
    public static void ExchangeClicksForSeconds(int numberOfSeconds, int adPackId, Member user)
    {
        AdPack     adPack     = new AdPack(adPackId);
        AdPackType adPackType = new AdPackType(adPack.AdPackTypeId);
        int        clicksLeft = (adPack.ClicksBought - adPack.TotalClicks) - 1;

        int maxExtraSecondsLeft = user.Membership.MaxExtraAdPackSecondsForClicks - (adPack.DisplayTime - adPackType.DisplayTime);

        if (numberOfSeconds > maxExtraSecondsLeft)
        {
            throw new MsgException(string.Format(U5006.CANNOTADDMORESECONDS, maxExtraSecondsLeft > 0 ? maxExtraSecondsLeft : 0));
        }

        int requiredClicks = GetReqiuredClicksForExchange(numberOfSeconds, adPackType);

        if (clicksLeft < requiredClicks)
        {
            throw new MsgException(string.Format(U5006.NOTENOUGHCLICKSFOREXCHANGE, requiredClicks + 1));
        }

        adPack.DisplayTime = adPack.DisplayTime + numberOfSeconds;

        adPack.ClicksBought = adPack.ClicksBought - requiredClicks;
        adPack.Save();
    }
Example #3
0
    public static void BuySurfAds(int adPacksAdvertId, Member user, SurfAdsPack surfAdsPack, PurchaseBalances targetBalance)
    {
        var availablePacks = SurfAdsPack.GetAllActivePacks();

        if (surfAdsPack.Status != SurfAdsPackStatus.Active)
        {
            throw new MsgException("Selected Surf Ads Pack is unavailable");
        }

        //BUY ADPACKS
        var totalPrice = surfAdsPack.Price;

        PurchaseOption.ChargeBalance(user, totalPrice, PurchaseOption.Features.SurfAd.ToString(), targetBalance, string.Format("{0} purchase", U5004.SURFADS));

        AdPacksAdvert ad = new AdPacksAdvert(adPacksAdvertId);

        AdPack pack = new AdPack();

        pack.MoneyReturned   = new Money(0);
        pack.AdPacksAdvertId = adPacksAdvertId;
        pack.TotalConstantBannerImpressions = pack.ConstantBannerImpressionsBought = 0;
        pack.NormalBannerImpressionsBought  = pack.TotalNormalBannerImpressions = 0;
        pack.ClicksBought         = surfAdsPack.Clicks;
        pack.PurchaseDate         = DateTime.Now;
        pack.MoneyToReturn        = pack.MoneyReturned = new Money(0);
        pack.UserCustomGroupId    = -1;
        pack.UserId               = user.Id;
        pack.DistributionPriority = new Decimal(0);
        pack.AdPackTypeId         = -1;
        pack.DisplayTime          = surfAdsPack.DisplayTime;
        pack.Save();

        //Pools
        PoolDistributionManager.AddProfit(ProfitSource.SurfAds, totalPrice);
    }
    public static void AddS4DSPack(Member user, int amountOfPacks)
    {
        for (int i = 0; i < amountOfPacks; i++)
        {
            var newS4DSPack = new AdPack();

            newS4DSPack.MoneyToReturn = Money.Parse("120");
            newS4DSPack.UserId        = user.Id;

            newS4DSPack.PurchaseDate      = DateTime.Now;
            newS4DSPack.MoneyReturned     = Money.Zero;
            newS4DSPack.UserCustomGroupId = -1;
            newS4DSPack.AdPackTypeId      = -1;

            newS4DSPack.Save();
        }
    }
Example #5
0
    public static void BuyPacks(int numberOfPacks, int adPacksAdvertId, Member user, AdPackType adPackType, PurchaseBalances targetBalance,
                                int?userGroupIdNullable = null, int?groupIdNullable = null, bool forcePurchaseWithoutDeducingFunds = false, Member adPackOwner = null)
    {
        if (!TitanFeatures.IsClickmyad && !AppSettings.RevShare.AdPack.EnableAdvertChange && adPacksAdvertId == -1 && AppSettings.RevShare.AdPacksPolicy != AppSettings.AdPacksPolicy.HYIP)
        {
            throw new MsgException(U6000.CANNOTBUYADPACKS);
        }

        AdPacksForOtherUsers record = null;
        string note = string.Format("{0} purchase", AppSettings.RevShare.AdPack.AdPackName);

        //Buying AdPacks for oneself
        if (adPackOwner == null)
        {
            if (!user.HasThisMembershipOrHigher(adPackType.RequiredMembership))
            {
                throw new MsgException(String.Format(U5006.YOUNEEDMEMBERSHIP, Membership.SelectName(adPackType.RequiredMembership)));
            }

            int numberOfUsersAdPacks = GetNumberOfUsersAdPacks(user.Id, true, adPackType.Id);

            if (numberOfUsersAdPacks + numberOfPacks > adPackType.MaxInstances)
            {
                throw new MsgException(U5004.TOOMANYADPACKOFTYPE.Replace("%a%", AppSettings.RevShare.AdPack.AdPackNamePlural)
                                       .Replace("%b%", (adPackType.MaxInstances - numberOfUsersAdPacks).ToString()));
            }

            int numberOfAllUsersAdpacks = GetNumberOfAllUsersAdPacks(user.Id, adPackType.Id);

            if (numberOfAllUsersAdpacks + numberOfPacks > adPackType.MaxInstancesOfAllAdpacks)
            {
                throw new MsgException(U5004.TOOMANYADPACKOFTYPE.Replace("%a%", AppSettings.RevShare.AdPack.AdPackNamePlural)
                                       .Replace("%b%", (adPackType.MaxInstancesOfAllAdpacks - numberOfAllUsersAdpacks).ToString()));
            }

            var availableTypes = AdPackTypeManager.GetAllActiveTypesForUser(user);

            if (!availableTypes.Any(el => el.Id == adPackType.Id) || adPackType.Status != AdPackTypeStatus.Active)
            {
                throw new MsgException("You cannot buy AdPacks of selected type.");
            }

            adPackOwner = user;
        }
        else
        {
            AdPacksForOtherUsers.Validate(user.Id, adPackOwner.Id, numberOfPacks, out record);
            note += " for " + adPackOwner.Name;
        }

        //BUY ADPACKS
        var totalPrice = GetAdPacksPrice(adPackType, numberOfPacks);

        if (!forcePurchaseWithoutDeducingFunds)
        {
            PurchaseOption.ChargeBalance(user, totalPrice, PurchaseOption.Features.AdPack.ToString(), targetBalance, note, BalanceLogType.AdPackPurchase);
        }

        if (user != adPackOwner)
        {
            AdPacksForOtherUsers.AddOrUpdate(record, user.Id, adPackOwner.Id, numberOfPacks);
        }


        Money totalTrafficExchangeSurfCredits = Money.Zero;
        int   totalLoginAdsCredits            = 0;

        for (int i = 0; i < numberOfPacks; i++)
        {
            AdPack pack = new AdPack();
            pack.MoneyReturned   = new Money(0);
            pack.AdPacksAdvertId = adPacksAdvertId;
            pack.TotalConstantBannerImpressions  = 0;
            pack.TotalNormalBannerImpressions    = 0;
            pack.ConstantBannerImpressionsBought = adPackType.ConstantBannerImpressions;
            pack.NormalBannerImpressionsBought   = adPackType.NormalBannerImpressions;
            pack.ClicksBought         = adPackType.Clicks;
            pack.PurchaseDate         = DateTime.Now;
            pack.MoneyReturned        = new Money(0);
            pack.MoneyToReturn        = Money.MultiplyPercent(adPackType.Price, adPackType.PackReturnValuePercentage + adPackOwner.Membership.ROIEnlargedByPercentage);
            pack.UserCustomGroupId    = -1;
            pack.UserId               = adPackOwner.Id;
            pack.DistributionPriority = new Decimal(1);
            pack.AdPackTypeId         = adPackType.Id;
            pack.DisplayTime          = adPackType.DisplayTime;
            pack.BalanceBoughtType    = targetBalance;
            pack.Save();

            totalTrafficExchangeSurfCredits += adPackType.TrafficExchangeSurfCredits;
            totalLoginAdsCredits            += adPackType.LoginAdsCredits;
        }

        if (AppSettings.TitanFeatures.AdvertTrafficExchangeEnabled)
        {
            adPackOwner.AddToTrafficBalance(totalTrafficExchangeSurfCredits, "Traffic Exchange Surf Credits", BalanceLogType.Other);
        }

        adPackOwner.AddToLoginAdsCredits(totalLoginAdsCredits, note);
        adPackOwner.SaveBalances();

        Money moneyLeftForPools;

        if (TitanFeatures.isAri)
        {
            AriRevShareDistribution.AdPackAriCrediter crediter = new AriRevShareDistribution.AdPackAriCrediter(user);
            moneyLeftForPools = crediter.CreditReferer(totalPrice, targetBalance);
        }
        else
        {
            AdPackCrediter crediter = new AdPackCrediter(user);
            moneyLeftForPools = crediter.CreditReferer(totalPrice);
        }

        //Pools
        if (TitanFeatures.StringSawSundayPool.HasValue && AppSettings.ServerTime.DayOfWeek == DayOfWeek.Sunday)
        {
            PoolDistributionManager.AddProfitToSundayPool(moneyLeftForPools);
        }
        else
        {
            PoolDistributionManager.AddProfit(ProfitSource.AdPacks, moneyLeftForPools);
        }

        //Matrix
        MatrixBase.TryAddMemberAndCredit(user, totalPrice, AdvertType.AdPack);

        var purchasedItem = PurchasedItem.Create(user.Id, adPackType.Price, numberOfPacks,
                                                 adPackType.Name + " " + AppSettings.RevShare.AdPack.AdPackName, PurchasedItemType.AdPack);

        if (TitanFeatures.isAri)
        {
            HtmlInvoiceGenerator generator = new HtmlInvoiceGenerator(purchasedItem);
            generator.SendPdfViaEmail();
        }

        //LeadershipSystem
        var list = new List <RestrictionKind>();

        list.Add(RestrictionKind.ActiveAdPacks);
        list.Add(RestrictionKind.ActiveAdPacksPrice);
        list.Add(RestrictionKind.DirectReferralsActiveAdPacks);
        list.Add(RestrictionKind.DirectReferralsActiveAdPacksPrice);
        LeadershipSystem.CheckSystem(list, user, 1);
    }