Beispiel #1
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                AppSettings.DemoCheck();
                Member User = Member.Current;

                NewBannerAdvert.Advertiser = Advertiser.AsMember(User.Name);
                NewBannerAdvert.Status     = AdvertStatusExtensions.GetStartingStatus();
                NewBannerAdvert.TargetUrl  = URL.Text;
                NewBannerAdvert.Pack       = new BannerAdvertPack();
                NewBannerAdvert.Price      = new Money(0);
                NewBannerAdvert.Dimensions = new BannerAdvertDimensions(Convert.ToInt32(BannerTypeRadioButtonList.SelectedValue));
                NewBannerAdvert.Save();

                //Referesh notifications
                SuccMessagePanel.Visible = true;
                SuccMessage.Text         = U3501.ADCREATED;

                Response.Redirect("bannersb.aspx?red=camp");

                Session["YourCampaigns_NewBannerAdvert"] = null;
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
Beispiel #2
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                string InURL = URL.Text;

                //Check fanpage in database
                if (FacebookAdvert.IsFanpageInDatabase(InURL))
                {
                    throw new MsgException(U6003.FANPAGEEXISTS);
                }

                //Validate Facebook URL
                if (!FacebookManager.IsFanpageURLValid(InURL))
                {
                    throw new MsgException(L1.ER_BADFBURL);
                }

                AppSettings.DemoCheck();

                FacebookAdvertPack Pack = new FacebookAdvertPack(Int32.Parse(ddlOptions.SelectedValue));
                FacebookAdvert     Ad   = new FacebookAdvert();
                Ad.TargetUrl = InURL;

                Money TotalCost = Pack.Price;
                if (chbFriends.Checked)
                {
                    Ad.MinFriends = Convert.ToInt32(ddlFriends.SelectedValue);
                    TotalCost    += AppSettings.Facebook.FriendsRestrictionsCost;
                }
                else
                {
                    Ad.MinFriends = 0;
                }

                if (chbProfilePicture.Checked)
                {
                    Ad.HasProfilePicRestrictions = true;
                    TotalCost += AppSettings.Facebook.ProfilePicRestrictionsCost;
                }
                else
                {
                    Ad.HasProfilePicRestrictions = false;
                }

                Member User = null;
                if (Member.IsLogged)
                {
                    User = Member.Current;

                    var targetBalance = TargetBalanceRadioButtonList.TargetBalance;
                    PurchaseOption.ChargeBalance(User, TotalCost, TargetBalanceRadioButtonList.Feature, targetBalance, "Facebook Ad credits");
                    Ad.TargetBalance = targetBalance;

                    Ad.Advertiser = Advertiser.AsMember(User.Name);
                    Ad.Status     = AdvertStatusExtensions.GetStartingStatus();
                }
                else
                {
                    Ad.Advertiser = Advertiser.AsStranger(OutEmail.Text);
                    Ad.Status     = AdvertStatus.Null;
                }

                Ad.Price = TotalCost;
                Ad.Pack  = Pack;
                Ad.Save();

                if (Member.IsLogged)
                {
                    //Add history entry 1
                    History.AddPurchase(User.Name, Ad.Price, "Facebook campaign");
                    //Add history entry 2
                    History.AddPurchase(User.Name, Pack.Price, Pack.Ends.Value + " Facebook likes");

                    //Achievements trial
                    int  UserCurrentCampaigns = TableHelper.CountOf <FacebookAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name));
                    bool ShouldBeSaved        = User.TryToAddAchievements(
                        Prem.PTC.Achievements.Achievement.GetProperAchievements(
                            Prem.PTC.Achievements.AchievementType.AfterAdvertisingFacebookCampaigns, UserCurrentCampaigns));

                    if (ShouldBeSaved)
                    {
                        User.Save();
                    }

                    //Show success panel
                    SuccMessagePanel.Visible = true;
                    SuccMessage.Text         = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED;

                    MatrixBase.TryAddMemberAndCredit(User, Ad.Price, AdvertType.Facebook);
                }
                else
                {
                    //Show buttons
                    PaymentButtons.Visible = true;
                    CreateAdButton.Visible = false;

                    PaymentButtons.Text = GenerateHTMLButtons.GetPaymentButtons(new BuyAdvertButtonGenerator <IFacebookAdvertPack>(Ad));
                }
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
Beispiel #3
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                AppSettings.DemoCheck();
                Member User = null;

                if (Member.IsLogged)
                {
                    User = Member.Logged(Context);
                }
                else
                {
                    Response.Redirect("~/default.aspx");
                }

                if (URL.Enabled)
                {
                    throw new MsgException(U4200.CHECKURL);
                }

                TrafficExchangeAdvert     Ad   = new TrafficExchangeAdvert();
                TrafficExchangeAdvertPack Pack = new TrafficExchangeAdvertPack(Int32.Parse(ddlOptions.SelectedValue));
                Money AdCost = Pack.Price;

                //Set basics
                Ad.Title     = InputChecker.HtmlEncode(Title.Text, Title.MaxLength, L1.TITLE);
                Ad.TargetUrl = URL.Text;

                if (TrafficSourceList.SelectedValue == "Anon")
                {
                    Ad.Description = TrafficSource.Anonymous;
                }
                else
                {
                    Ad.Description = TrafficSource.ThisWebsite;
                }

                if (chbGeolocation.Checked)
                {
                    AdCost += AppSettings.PtcAdverts.GeolocationCost;

                    //Now get it from client-state
                    var CTable   = Request.Form[GeoCountriesValues.Name].Substring(1).Split('#');
                    var geoUList = GeolocationUtils.GeoCountData.Keys;

                    foreach (string s in CTable)
                    {
                        if (geoUList.Contains <string>(s))
                        {
                            Ad.GeolocatedCountries += CountryManager.GetCountryCode(s) + ",";
                        }
                    }
                }

                if (Member.IsLogged)
                {
                    //Take money and save the user
                    var note = TitanFeatures.IsAhmed ? "Flash Traffic advertising" : "Traffic Exchange advertising";
                    PurchaseOption.ChargeBalance(User, AdCost, PurchaseBalances.Traffic, note);

                    Ad.Advertiser = Advertiser.AsMember(User.Name);
                    Ad.Status     = AdvertStatusExtensions.GetStartingStatus();
                }

                //Add the ad to the db (for approval)
                Ad.Price = AdCost;
                Ad.Pack  = Pack;
                Ad.Save();

                if (Member.IsLogged)
                {
                    //Add history entry 1
                    if (TitanFeatures.IsAhmed)
                    {
                        History.AddPurchase(User.Name, AdCost, "Flash Traffic advertising");
                    }
                    else
                    {
                        History.AddPurchase(User.Name, AdCost, "Traffic Exchange advertising");
                    }

                    //Add history entry 2
                    string entryText = "";
                    if (Pack.Ends.EndMode == End.Mode.Clicks)
                    {
                        entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad clicks";
                    }
                    else if (Pack.Ends.EndMode == End.Mode.Days)
                    {
                        entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad days";
                    }

                    History.AddPurchase(User.Name, Pack.Price, entryText);

                    Title.Text             = "";
                    URL.Text               = "";
                    URL.Enabled            = true;
                    CheckURLButton.Visible = true;

                    SuccMessagePanel.Visible = true;
                    SuccMessage.Text         = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED;
                }
                UsersTrafficBalanceLabel.Text = string.Format(U6008.YOURTRAFFICBALANCE, Member.CurrentInCache.TrafficBalance);
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
Beispiel #4
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                AppSettings.DemoCheck();
                Member User = null;

                if (Member.IsLogged)
                {
                    User = Member.Logged(Context);
                }

                if (URL.Enabled)
                {
                    throw new MsgException(U4200.CHECKURL);
                }

                TrafficGridAdvert     Ad   = new TrafficGridAdvert();
                TrafficGridAdvertPack Pack = new TrafficGridAdvertPack(Int32.Parse(ddlOptions.SelectedValue));
                Money AdCost = Pack.Price;

                //Set basics
                Ad.Title     = InputChecker.HtmlEncode(Title.Text, Title.MaxLength, L1.TITLE);
                Ad.TargetUrl = URL.Text;

                if (Member.IsLogged)
                {
                    //Take money and save the user
                    var targetBalance = TargetBalanceRadioButtonList.TargetBalance;
                    PurchaseOption.ChargeBalance(User, AdCost, TargetBalanceRadioButtonList.Feature, targetBalance, "TrafficGrid advertising");

                    Ad.TargetBalance = targetBalance;
                    Ad.Advertiser    = Advertiser.AsMember(User.Name);
                    Ad.Status        = AdvertStatusExtensions.GetStartingStatus();
                }
                else
                {
                    Ad.Advertiser = Advertiser.AsStranger(OutEmail.Text);
                    Ad.Status     = AdvertStatus.Null;
                }

                //Add the ad to the db (for approval)
                Ad.Price = AdCost;
                Ad.Pack  = Pack;
                Ad.Save();

                if (Member.IsLogged)
                {
                    if (Ad.Status == AdvertStatus.Active || Ad.Status == AdvertStatus.Paused)
                    {
                        var Crediter = (TrafficGridCrediter)CrediterFactory.Acquire(User, Titan.CreditType.TrafficGrid);
                        Crediter.CreditReferer(AdCost);
                    }

                    //Achievements trial
                    int  UserCurrentCampaigns = TableHelper.CountOf <TrafficGridAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name));
                    bool ShouldBeSaved        = User.TryToAddAchievements(
                        Prem.PTC.Achievements.Achievement.GetProperAchievements(
                            Prem.PTC.Achievements.AchievementType.AfterAdvertisingTrafficGridCampaigns, UserCurrentCampaigns));

                    if (ShouldBeSaved)
                    {
                        User.Save();
                    }

                    //Add history entry 1
                    History.AddPurchase(User.Name, AdCost, "TrafficGrid campaign");

                    //Add history entry 2
                    string entryText = "";
                    if (Pack.Ends.EndMode == End.Mode.Clicks)
                    {
                        entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad clicks";
                    }
                    else if (Pack.Ends.EndMode == End.Mode.Days)
                    {
                        entryText = (Convert.ToInt32(Pack.Ends.Value)).ToString() + " ad days";
                    }

                    History.AddPurchase(User.Name, Pack.Price, entryText);

                    Title.Text               = "";
                    URL.Text                 = "";
                    URL.Enabled              = true;
                    CheckURLButton.Visible   = true;
                    SuccMessagePanel.Visible = true;
                    SuccMessage.Text         = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED;

                    MatrixBase.TryAddMemberAndCredit(User, Ad.Price, AdvertType.TrafficGrid);
                }
                else
                {
                    //Show buttons
                    CreateAdButton.Visible = false;

                    PaymentButtons.Visible = true;
                    PaymentButtons.Text    = GenerateHTMLButtons.GetPaymentButtons(new BuyAdvertButtonGenerator <ITrafficGridAdvertPack>(Ad));
                }
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
Beispiel #5
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                AppSettings.DemoCheck();
                Member User = null;

                if (Member.IsLogged)
                {
                    User = Member.Logged(Context);
                }

                if (ddlOptions.SelectedItem == null)
                {
                    throw new MsgException(U6002.BANNERPACKERROR);
                }

                BannerAdvertPack Pack   = new BannerAdvertPack(Int32.Parse(ddlOptions.SelectedValue));
                Money            AdCost = Pack.Price;

                if (chbGeolocation.Checked)
                {
                    AdCost += AppSettings.BannerAdverts.GeolocationCost;

                    //Now get it from client-state
                    var CTable   = Request.Form[GeoCountriesValues.Name].Substring(1).Split('#');
                    var geoUList = GeolocationUtils.GeoCountData.Keys;

                    foreach (string s in CTable)
                    {
                        if (geoUList.Contains <string>(s))
                        {
                            NewBannerAdvert.BannedCountries.Add(s);
                        }
                    }
                }

                if (Member.IsLogged)
                {
                    var targetBalance = TargetBalanceRadioButtonList.TargetBalance;
                    PurchaseOption.ChargeBalance(User, AdCost, TargetBalanceRadioButtonList.Feature, targetBalance, "Banner campaign");

                    NewBannerAdvert.Advertiser    = Advertiser.AsMember(User.Name);
                    NewBannerAdvert.Status        = AdvertStatusExtensions.GetStartingStatus();
                    NewBannerAdvert.TargetBalance = targetBalance;
                }
                else
                {
                    NewBannerAdvert.Advertiser = Advertiser.AsStranger(OutEmail.Text);
                    NewBannerAdvert.Status     = AdvertStatus.Null;
                }

                //Set basics - add to db
                NewBannerAdvert.TargetUrl = URL.Text;
                NewBannerAdvert.Pack      = Pack;
                NewBannerAdvert.Price     = AdCost;
                NewBannerAdvert.Save();

                if (Member.IsLogged)
                {
                    if (AppSettings.BannerAdverts.AdvertisingPolicy != BannerPolicy.BannerBidding &&
                        (NewBannerAdvert.Status == AdvertStatus.Active || NewBannerAdvert.Status == AdvertStatus.Paused))
                    {
                        BannerCrediter crediter          = new BannerCrediter(User);
                        Money          moneyLeftForPools = crediter.CreditReferer(NewBannerAdvert.Price);

                        PoolDistributionManager.AddProfit(ProfitSource.Banners, moneyLeftForPools);
                    }

                    //Achievements trial
                    int UserCurrentCampaigns =
                        TableHelper.CountOf <BannerAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name));
                    bool ShouldBeSaved = User.TryToAddAchievements(
                        Prem.PTC.Achievements.Achievement.GetProperAchievements(
                            Prem.PTC.Achievements.AchievementType.AfterAdvertisingBannerCampaigns, UserCurrentCampaigns));

                    if (ShouldBeSaved)
                    {
                        User.Save();
                    }

                    //Add history entry 1
                    History.AddPurchase(User.Name, AdCost, "Banner campaign");

                    SuccMessagePanel.Visible = true;
                    SuccMessage.Text         = U3501.ADCREATED;

                    //Earning stats
                    EarningsStatsManager.Add(EarningsStatsType.Banner, AdCost);

                    MatrixBase.TryAddMemberAndCredit(User, AdCost, AdvertType.Banner);

                    Response.Redirect("banners.aspx");
                }
                else
                {
                    //Show buttons
                    PaymentButtons.Visible = true;
                    CreateAdButton.Visible = false;

                    PaymentButtons.Text =
                        GenerateHTMLButtons.GetPaymentButtons(
                            new BuyAdvertButtonGenerator <IBannerAdvertPack>(NewBannerAdvert));
                }

                Session["YourCampaigns_NewBannerAdvert"] = null;
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
                throw ex;
            }
        }
    }
Beispiel #6
0
    protected void CreateAdButton_Click(object sender, EventArgs e)
    {
        ErrorMessagePanel.Visible = false;
        SuccMessagePanel.Visible  = false;

        if (Page.IsValid)
        {
            try
            {
                AppSettings.DemoCheck();
                Member User      = null;
                int    oldPackId = 0;

                if (Member.IsLogged)
                {
                    User = Member.Logged(Context);
                }

                if (URL.Enabled)
                {
                    throw new MsgException(U4200.CHECKURL);
                }

                PtcAdvert Ad;
                if (PageRequest == RequestType.Edit)
                {
                    int adId = Convert.ToInt32(ViewState["editid"]);
                    Ad        = new PtcAdvert(adId);
                    oldPackId = Ad.Pack.Id;
                }
                else
                {
                    Ad = new PtcAdvert();
                }

                Money         AdCost = Money.Zero;
                PtcAdvertPack Pack   = new PtcAdvertPack();

                GetAdWithPrice(ref Ad, ref AdCost, ref Pack);

                //Add the ad to the db (for approval)
                Ad.Price = AdCost;
                if (Pack != null)
                {
                    Ad.Pack = Pack;
                }

                if (Member.IsLogged)
                {
                    //Take money and save the user
                    int adViews = 0;
                    if (AppSettings.PtcAdverts.PTCCreditsEnabled && UseExtraViewsCheckBox.Checked)
                    {
                        adViews = Convert.ToInt32(PTCCreditsTextBox.Text);
                        if (adViews < 0)
                        {
                            throw new MsgException("Input cannot be negative.");
                        }

                        decimal adCreditsSpent       = 0;
                        var     creditsPerDayOrClick = 0m;
                        if (Pack == null)
                        {
                            if (TitanFeatures.isSatvetErturkmen)
                            {
                                PtcAdvertPack advertPack = TableHelper.GetListFromRawQuery <PtcAdvertPack>("SELECT TOP 1 * FROM PtcAdvertPacks")[0];
                                Ad.Pack = advertPack;
                                Ad.Ends = End.FromClicks(adViews);
                                creditsPerDayOrClick = advertPack.PTCCreditsPerDayOrClick;
                            }
                        }
                        else
                        {
                            Ad.Ends = Ad.Ends.AddValue(adViews);
                            creditsPerDayOrClick = Pack.PTCCreditsPerDayOrClick;
                        }

                        if (PageRequest == RequestType.Edit && Ad.ExtraViews != -1)
                        {
                            adCreditsSpent = (adViews - Ad.ExtraViews) * creditsPerDayOrClick;
                            if (adCreditsSpent < 0)
                            {
                                adCreditsSpent = 0;
                            }
                        }
                        else
                        {
                            adCreditsSpent = adViews * creditsPerDayOrClick;
                        }

                        Ad.ExtraViews = adViews;

                        if (adCreditsSpent > Member.Current.PTCCredits)
                        {
                            throw new MsgException(U5006.NOTENOUGHADCREDITS);
                        }
                        else
                        {
                            User.SubstractFromPTCCredits(adCreditsSpent, "PTC advert");
                        }
                    }
                    else
                    {
                        Ad.ExtraViews = -1;
                    }

                    if (PageRequest == RequestType.Edit)
                    {
                        Ad.IsEdited = true;
                    }

                    Ad.TargetBalance = TargetBalanceRadioButtonList.TargetBalance;
                    PurchaseOption.ChargeBalance(User, AdCost, TargetBalanceRadioButtonList.Feature, Ad.TargetBalance, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert");

                    Ad.Advertiser       = Advertiser.AsMember(User.Name);
                    Ad.AdvertiserUserId = User.Id;
                    Ad.Status           = AdvertStatusExtensions.GetStartingStatus();

                    if (AppSettings.PtcAdverts.AdvertPTCPackCashbackEnabled && Pack.PTCPackCashBackPercent != 0)
                    {
                        Money CashBack = new Money(Double.Parse(AdCost.ToClearString()) * ((Double)Pack.PTCPackCashBackPercent / 100.0));
                        User.AddToTrafficBalance(CashBack, U6010.PTCCASHBACK);
                        User.Save();
                    }
                }
                else
                {
                    Ad.Advertiser    = Advertiser.AsStranger(OutEmail.Text);
                    Ad.TargetBalance = PurchaseBalances.PaymentProcessor;
                    Ad.Status        = AdvertStatus.Null;
                }

                if (oldPackId != 0 && oldPackId != Ad.Pack.Id)
                {
                    Ad.ResetClicks();
                }

                Ad.Save();

                if (Member.IsLogged)
                {
                    //Achievements trial
                    int  UserCurrentCampaigns = TableHelper.CountOf <PtcAdvert>(TableHelper.MakeDictionary("CreatorUsername", User.Name));
                    bool ShouldBeSaved        = User.TryToAddAchievements(
                        Prem.PTC.Achievements.Achievement.GetProperAchievements(
                            Prem.PTC.Achievements.AchievementType.AfterAdvertisingPtcCampaigns, UserCurrentCampaigns));

                    if (ShouldBeSaved)
                    {
                        User.Save();
                    }

                    if (PageRequest == RequestType.Edit)
                    {
                        History.AddEdit(User.Name, AdCost, "Advert campaign");
                    }
                    else
                    {
                        History.AddPurchase(User.Name, AdCost, "Advert campaign");

                        MatrixBase.TryAddMemberAndCredit(User, AdCost, AdvertType.PTC);
                    }

                    if (Ad.Status != AdvertStatus.WaitingForAcceptance)
                    {
                        PtcCrediter.TryToCreditReferrerAfterPurchase(User, AdCost, PageRequest == RequestType.Edit ? "PTC update" : "PTC advert");
                    }

                    Title.Text                      = "";
                    URL.Text                        = "";
                    chbDescription.Checked          = false;
                    chbGeolocation.Checked          = false;
                    chbBold.Checked                 = false;
                    BackgroundColorCheckBox.Checked = false;
                    StarredAdCheckBox.Checked       = false;

                    SuccMessagePanel.Visible = true;

                    if (PageRequest == RequestType.Edit)
                    {
                        SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U6012.EDITEDADAWAITSAPPROVAL : U6012.ADUPDATED;
                    }
                    else
                    {
                        SuccMessage.Text = Ad.Status == AdvertStatus.WaitingForAcceptance ? U4200.ADAWAITSAPPROVAL : U3501.ADCREATED;
                    }
                }
                else
                {
                    //Show buttons
                    PaymentButtons.Visible = true;
                    CreateAdButton.Visible = false;

                    PaymentButtons.Text = GenerateHTMLButtons.GetPaymentButtons(new BuyAdvertButtonGenerator <IPtcAdvertPack>(Ad));
                }

                ViewState["editid"] = null;
            }
            catch (MsgException ex)
            {
                ErrorMessagePanel.Visible = true;
                ErrorMessage.Text         = ex.Message;
            }
            catch (Exception ex)
            {
                ErrorLogger.Log(ex);
            }
        }
    }