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; } } }