public void Test() { BuddyImporterService service = new BuddyImporterService(); string email = "*****@*****.**"; Usr u = new Usr(); u.Update(); Usr u2 = new Usr() { Email = email }; u2.Update(); Buddy b = new Buddy() { UsrK = u.K, BuddyUsrK = u2.K }; b.Update(); List<Contact> cList; List<Usr> uList; List<Contact> list = new List<Contact>() { new Contact("Bob", email) }; int alreadyBuddies; service.SplitOutEmailContacts(list, u.K, out alreadyBuddies, out uList, out cList); Assert.AreEqual(1, uList.Count); Assert.IsTrue((bool)uList[0].ExtraSelectElements["BuddyRequested"]); Assert.AreEqual(0, cList.Count); }
public void SetBuddyInvite(Usr buddyUsr, bool allowBuddyInvite, AddBuddySource source, Buddy.BuddyFindingMethod? foundByMethod, string skeletonName) { if (allowBuddyInvite && !foundByMethod.HasValue) { throw new ArgumentNullException("foundByMethod", "Must have a method when allowBuddyInvite is true"); } ValidateBuddyUsr(buddyUsr); if (this.HasBuddy(buddyUsr.K)) { try { Buddy buddy = new Buddy(this.K, buddyUsr.K); buddy.CanBuddyInvite = allowBuddyInvite; buddy.Update(); #region update reverse buddy try { Buddy reverseBuddy = new Buddy(buddyUsr.K, this.K); reverseBuddy.CanInvite = allowBuddyInvite; reverseBuddy.Update(); } catch (BobNotFound) { } #endregion } catch (Exception ex) { throw ex; } } else if (allowBuddyInvite) { this.AddBuddy(buddyUsr, source, foundByMethod.Value, skeletonName ); } }
public void DenyBuddy(int buddyUsrK, bool deny) { if (deny == true) { try { Buddy b = new Buddy(buddyUsrK, this.K); b.Denied = true; b.FullBuddy = false; b.CanInvite = false; b.CanBuddyInvite = false; b.Update(); } catch (BobNotFound) { Buddy b = new Buddy(); b.UsrK = buddyUsrK; b.BuddyUsrK = this.K; b.Denied = true; b.Update(); } try { Buddy b = new Buddy(this.K, buddyUsrK); b.Delete(); b.Update(); } catch (BobNotFound) { } } else { try { Buddy b = new Buddy(buddyUsrK, this.K); b.Denied = false; b.Update(); } catch (BobNotFound) { } } }
public void RemoveBuddy(int BuddyUsrK) { try { Buddy b = new Buddy(this.K, BuddyUsrK); b.Delete(); b.Update(); b.Usr.UpdateBuddyCount(null); b.BuddyUsr.UpdateBuddyCount(null); } catch { } try { Buddy b = new Buddy(BuddyUsrK, this.K); b.FullBuddy = false; b.Update(); b.Usr.UpdateBuddyCount(null); b.BuddyUsr.UpdateBuddyCount(null); } catch { } }
public void AddBuddy(Usr buddyUsr, bool canBuddyInvite, bool sendNotificationEmailIfNewBuddyRequest, AddBuddySource source, Buddy.BuddyFindingMethod foundByMethod, string skeletonName) { ValidateBuddyUsr(buddyUsr, true); Buddy b; try { b = new Buddy(this.K, buddyUsr.K); } catch (BobNotFound) { b = new Buddy(); b.UsrK = this.K; b.BuddyUsrK = buddyUsr.K; b.CanBuddyInvite = canBuddyInvite; b.BuddyFoundByMethod = foundByMethod; b.SkeletonName = skeletonName; try { Buddy reverseBuddy = new Buddy(buddyUsr.K, this.K); reverseBuddy.FullBuddy = true; reverseBuddy.Denied = false; reverseBuddy.CanInvite = canBuddyInvite; b.CanInvite = reverseBuddy.CanBuddyInvite; b.FullBuddy = true; b.Denied = false; reverseBuddy.Update(); if (this.FacebookConnected && this.FacebookStoryNewBuddy) { try { FacebookPost.CreateNewBuddy(this, buddyUsr, true); } catch { } } if (buddyUsr.FacebookConnected && buddyUsr.FacebookStoryNewBuddy) { try { FacebookPost.CreateNewBuddy(buddyUsr, this, false); } catch { } } } catch (BobNotFound) { if (source == AddBuddySource.BuddyButtonClick || source == AddBuddySource.UsrPageSendPrivateMessage) { Usr.IncrementSpamBotDefeaterCounter(SpamBotDefeaterCounter.BuddyRequests, this.K); } b.CanInvite = false; b.FullBuddy = false; if (sendNotificationEmailIfNewBuddyRequest) { Mailer m = new Mailer(); m.TemplateType = Mailer.TemplateTypes.AnotherSiteUser; m.Subject = this.NickName + " has invited you to " + this.HisString(false) + " buddy list"; if (this.HasPic) { m.Body += "<a href=\"[LOGIN(" + this.Url() + ")]\"><img src=\"" + this.PicPath + "\" style=\"margin-left:5px;\" class=\"BorderBlack All\" width=\"100\" height=\"100\" align=\"right\" vspace=\"6\" border=\"0\"></a>"; } m.Body += "<h1>" + HttpUtility.HtmlEncode(this.NickName) + " has invited you to " + this.HisString(false) + " buddy list</h1>"; m.Body += "<p>Name: <a href=\"[LOGIN(" + this.Url() + ")]\">" + HttpUtility.HtmlEncode(this.FirstName) + " " + HttpUtility.HtmlEncode(this.LastName) + "</a>.</p>"; m.Body += "<p>To add " + HttpUtility.HtmlEncode(this.NickName) + " to your buddy list, view " + this.HisString(false) + " <a href=\"[LOGIN(" + this.Url() + ")]\">profile</a> and click the \"Add " + HttpUtility.HtmlEncode(this.NickName) + " to my buddy list\" button.</p>"; m.OverrideLoginLink = buddyUsr.LoginAndTransfer(this.Url()); m.UsrRecipient = buddyUsr; m.To = buddyUsr.Email; m.Send(); } } b.Update(); b.Usr.UpdateBuddyCount(null); b.BuddyUsr.UpdateBuddyCount(null); } }