protected void DirectRefsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { //We want to obey OnSort and OnChart events string[] commands = new string[3] { "start", "stop", "remove" }; if (commands.Contains(e.CommandName)) { int index = e.GetSelectedRowIndex() % DirectRefsGridView.PageSize; GridViewRow row = DirectRefsGridView.Rows[index]; var Ad = new FacebookAdvert(Convert.ToInt32(row.Cells[1].Text.Trim())); if (e.CommandName == "start") { Ad.Status = AdvertStatus.Active; Ad.SaveStatus(); DirectRefsGridView.DataBind(); } else if (e.CommandName == "stop") { Ad.Status = AdvertStatus.Paused; Ad.SaveStatus(); DirectRefsGridView.DataBind(); } else if (e.CommandName == "remove") { Ad.Status = AdvertStatus.Deleted; Ad.SaveStatus(); DirectRefsGridView.DataBind(); } } }
protected void DirectRefsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { FacebookAdvert Ad = new FacebookAdvert(Convert.ToInt32(e.Row.Cells[1].Text)); //[5] ProfilePic var check = (CheckBox)e.Row.Cells[5].Controls[0]; if (check.Checked) { e.Row.Cells[5].Text = HtmlCreator.GetCheckboxCheckedImage(); } else { e.Row.Cells[5].Text = HtmlCreator.GetCheckboxUncheckedImage(); } //Progress [13] e.Row.Cells[13].Text = HtmlCreator.GenerateAdProgressHTML(Ad).Replace("clicks", L1.LIKESSMALL); // % [14] e.Row.Cells[14].Text = Ad.ProgressInPercent + "%"; // Likes (Clicks) [15] e.Row.Cells[15].Text = Ad.Clicks.ToString(); //Status [16] e.Row.Cells[16].Text = HtmlCreator.GetColoredStatus(Ad.Status); //start [19] stop [20] remove[21] if (Ad.Status != AdvertStatus.Paused) { e.Row.Cells[19].Text = " "; } if (Ad.Status != AdvertStatus.Active) { e.Row.Cells[20].Text = " "; } if (!Ad.Status.CanBeRemoved()) { e.Row.Cells[21].Text = " "; } } }
private static bool HasUserMeetRequirements(FacebookAdvert Ad, FacebookMember FbMember) { bool IsOKWithRequirements = true; //Profile pic if (Ad.HasProfilePicRestrictions && !FbMember.HasProfilePicture) { IsOKWithRequirements = false; } //Friends if (Ad.MinFriends > 0 && FbMember.Friends < Ad.MinFriends) { IsOKWithRequirements = false; } return(IsOKWithRequirements); }
public void CreditMember(FacebookAdvert Ad, bool credit) { //OK mark as watched and credit List <int> av = User.AdsLiked; int userPoints, referrerPoints; if (credit) { av.Add(Ad.Id); userPoints = AppSettings.Facebook.PointsPerLike; referrerPoints = AppSettings.Facebook.DirectReferralPointsPerLike; User.FbLikesToday++; } else { av.Remove(Ad.Id); userPoints = -AppSettings.Facebook.PointsPerLike; referrerPoints = -AppSettings.Facebook.DirectReferralPointsPerLike; } User.AdsLiked = av; //base.CreditMainBalance(Calculated); base.CreditPoints(userPoints, "Facebook", BalanceLogType.Other); try { if (AppSettings.Facebook.CreditOnlyUsersWhoPuchasedFacebookMembership && User.Membership.Id == Membership.Standard.Id) { } else { var referrer = new Member(User.ReferrerId); CreditPoints(referrer, referrerPoints, "Facebook /ref/" + User.Name, BalanceLogType.Other); referrer.Save(); } } catch (Exception e) { } User.Save(); }
protected void FacebookLikesGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { FacebookAdvert Ad = new FacebookAdvert(Convert.ToInt32(e.Row.Cells[0].Text)); //[2] Profile picture var check = (CheckBox)e.Row.Cells[2].Controls[0]; if (check.Checked) { e.Row.Cells[2].Text = HtmlCreator.GetCheckboxCheckedImage(); } else { e.Row.Cells[2].Text = HtmlCreator.GetCheckboxUncheckedImage(); } //[3] Facebook like button e.Row.Cells[3].Text = FacebookMember.GetLikeButtonCode(Ad); if (FbUser != null && !User.AdsLiked.Contains(Ad.Id)) { e.Row.Cells[1].Text += String.Format(" ({0} {1})", L1.YOUHAVE, FbUser.Friends); if (FbUser.Friends >= Ad.MinFriends) { e.Row.Cells[1].ForeColor = System.Drawing.Color.Green; } else { e.Row.Cells[1].ForeColor = System.Drawing.Color.DarkRed; } if (Ad.HasProfilePicRestrictions && !FbUser.HasProfilePicture) { e.Row.Cells[2].Text = L1.NEEDED.ToUpper(); e.Row.Cells[2].ForeColor = System.Drawing.Color.DarkRed; } else { e.Row.Cells[2].Text = "OK"; e.Row.Cells[2].ForeColor = System.Drawing.Color.Green; } } if (AppSettings.Facebook.CustomFacebookLikesEnabled) { //[4] Titan like button LinkButton btn = e.Row.FindControl("LikeButton") as LinkButton; if (FbUser != null && !User.AdsLiked.Contains(Ad.Id) && FbUser.Friends >= Ad.MinFriends && (!Ad.HasProfilePicRestrictions || Ad.HasProfilePicRestrictions && FbUser.HasProfilePicture)) { btn.ToolTip = "Like"; btn.CommandName = "like"; btn.Text = "<span class=\"fa fa-plus fa-lg text-success\"></span>"; } else { btn.ToolTip = "Forbidden"; btn.Text = "<span class=\"fa fa-times fa-lg text-danger\"></span>"; btn.Enabled = false; } } } }
public static string LikeUnlike(string adId, bool credit) { string succMsg = string.Empty; if (FacebookMember.Logged() != null) { Member User = Member.Current; FacebookMember FbUser; FacebookAdvert Ad = new FacebookAdvert(Convert.ToInt32(adId)); FbUser = new FacebookMember(FacebookMember.Logged()); //Facebook security (banning multiple accounts instantly) User.FacebookName = FbUser.Name; User.Save(); AntiCheatSystem.AfterFacebookLogin(User); if (FbUser == null) { return(U5008.MUSTCONNECTFB); } if (!HasUserMeetRequirements(Ad, FbUser)) { return(L1.NOTMEETREQUIREMENTS); } var userLikes = User.FbLikesToday; var maxLikes = User.Membership.MaxFacebookLikesPerDay; if (userLikes >= maxLikes) { return(string.Format(U6004.REACHEDMAXLIKESPERDAY, maxLikes)); } HttpContext.Current.Session["fbcookie"] = "notok"; if (credit) { Ad.Click(); succMsg = U3501.YOUHAVEBEENCREDITED + " (" + AppSettings.Facebook.PointsPerLike + " " + AppSettings.PointsName + ")"; } else { Ad.Unclick(); succMsg = string.Format(U5008.POINTSREVERSED, AppSettings.Facebook.PointsPerLike + " " + AppSettings.PointsName); } if (Ad.ShouldBeFinished) { Ad.Status = AdvertStatus.Finished; } Ad.SaveClicks(); Ad.Save(); //Use Crediter FacebookCrediter Crediter = (FacebookCrediter)CrediterFactory.Acquire(User, CreditType.FacebookLike); Crediter.CreditMember(Ad, credit); NotificationManager.RefreshWithMember(NotificationType.NewFacebookAds, User); return(succMsg); } else { return(U5008.MUSTCONNECTFB); } }
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; } } }
public static string GetLikeButtonCode(FacebookAdvert ad) { string code = "<div class=\"fb-like\" data-ad-id=\"" + ad.Id + "\" data-href=\"" + ad.TargetUrl + "\" data-action=\"like\" data-layout=\"standard\" data-width=\"450\" data-show-faces=\"false\"></div>"; return(code); }