private void LoadNotifications() { var member = LoggedInMember; if (member != null) { // Get set of pending invitations. _notifications = new List <object>(); var friendInvitations = _memberFriendsQuery.GetFriendInvitations(member.Id, member.GetBestEmailAddress().Address); foreach (var invitation in friendInvitations) { _notifications.Add(invitation); } var representativeInvitations = _memberFriendsQuery.GetRepresentativeInvitations(member.Id, member.GetBestEmailAddress().Address); foreach (var invitation in representativeInvitations) { _notifications.Add(invitation); } var contactIds = (from i in friendInvitations select i.InviterId) .Concat(from i in representativeInvitations select i.InviterId); _views = _memberViewsQuery.GetPersonalViews(member.Id, contactIds); } else { _notifications = new List <object>(); _views = new PersonalViews(); } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); var invitations = _memberFriendsQuery.GetFriendInvitations(_member.Id); _representativeInvitation = _memberFriendsQuery.GetRepresentativeInvitationByInviter(Member.Id); var contactIds = from i in invitations where i.InviteeId != null select i.InviteeId.Value; if (_representativeInvitation != null && _representativeInvitation.InviteeId != null) { contactIds = contactIds.Concat(new[] { _representativeInvitation.InviteeId.Value }); } _views = _memberViewsQuery.GetPersonalViews(_member.Id, contactIds); rptSentInvitations.DataSource = invitations; rptSentInvitations.DataBind(); if (invitations.Count == 0) { rptSentInvitations.Visible = false; phNoSentInvitations.Visible = true; phSentInvitations.Visible = false; } phSentRepresentativeInvitation.Visible = _representativeInvitation != null; }
private void InitialiseInvitations() { var friendInvitations = _memberFriendsQuery.GetFriendInvitations(LoggedInMember.Id, LoggedInMember.GetBestEmailAddress().Address); var representativeInvitations = _memberFriendsQuery.GetRepresentativeInvitations(LoggedInMember.Id, LoggedInMember.GetBestEmailAddress().Address); var allIds = (from i in friendInvitations select i.InviterId) .Concat(from i in representativeInvitations select i.InviterId); _views = _memberViewsQuery.GetPersonalViews(LoggedInUserId, allIds); if (friendInvitations.Count > 0) { rptInvitations.Visible = true; rptInvitations.DataSource = friendInvitations; rptInvitations.DataBind(); } else { rptInvitations.Visible = false; litNoInvitationsMessage.Visible = true; litNoInvitationsMessage.Text = NoPendingInvitations; } if (representativeInvitations.Count > 0) { phRepresentative.Visible = true; rptRepresentativeInvitations.DataSource = representativeInvitations; rptRepresentativeInvitations.DataBind(); } else { phRepresentative.Visible = false; } }
public bool SendInvitations() { Page.Validate(); if (!Page.IsValid) { return(false); } try { string[] emailAddresses = TextUtil.SplitEmailAddresses(txtEmailAddresses.Text); if (emailAddresses != null) { txtEmailAddresses.Text = ""; // Filter out all invalid emails var validEmails = new List <string>(); var invalidEmails = new List <string>(); var alreadyInvitedEmails = new Dictionary <String, DateTime>(); bool ownEmailSupplied = false; var existingInvites = _memberFriendsQuery.GetFriendInvitations(LoggedInMember.Id); foreach (string email in emailAddresses) { IValidator validator = EmailAddressValidatorFactory.CreateValidator(EmailAddressValidationMode.SingleEmail, false); var errors = validator.IsValid(email) ? null : validator.GetValidationErrors("EmailAddress"); if (errors == null || errors.Length == 0) { if ((String.Compare(LoggedInMember.GetBestEmailAddress().Address, email, true)) == 0) { ownEmailSupplied = true; continue; } var existingInvite = GetInviteForEmail(email, existingInvites); if (existingInvite != null && !_memberFriendsCommand.CanSendInvitation(existingInvite)) { if (existingInvite.LastSentTime == null) { throw new ArgumentNullException("The last sending time was not set, but invite sending was not allowed."); } alreadyInvitedEmails.Add(email, existingInvite.LastSentTime.Value); continue; } validEmails.Add(email); continue; } invalidEmails.Add(email); } // Create a donation request. DonationRequest request = GetDonationRequest(); // Create invitations. var duplicateFriends = SendFriendInvitations(LoggedInMember.Id, validEmails, txtBody.Text, request == null ? (Guid?)null : request.Id); foreach (string duplicateEmail in duplicateFriends) { validEmails.Remove(duplicateEmail); } // Display all errors if (invalidEmails.Count > 0) { string invalidEmailsToReproccess = String.Empty; for (int i = 0; i < invalidEmails.Count; i++) { if (i != 0) { invalidEmailsToReproccess += ","; } invalidEmailsToReproccess += invalidEmails[i]; } txtEmailAddresses.Text = invalidEmailsToReproccess; // Setup the styles to display the mock validator inline txtEmailAddresses.Style.Add("float", "left"); invalidEmailsPanel.Style.Add("float", "left"); invalidEmailsPanel.Style.Add("width", "160px"); invalidEmailsPanel.Style.Add("padding-left", "20px"); // Show the error image and display error text invalidEmailsPanel.Visible = true; } if (duplicateFriends.Count > 0) { alreadyFriendsPanel.Visible = true; var sb = new StringBuilder(); foreach (string email in duplicateFriends) { sb.AppendLine(email + "<br />"); } alreadyFriendsList.InnerHtml = sb.ToString(); } if (alreadyInvitedEmails.Keys.Count > 0) { duplicateInvitesPanel.Visible = true; var sb = new StringBuilder(); foreach (KeyValuePair <String, DateTime> emailAndDatePair in alreadyInvitedEmails) { int resendableDays = Container.Current.Resolve <int>("linkme.domain.roles.networking.invitationResendableDays"); DateTime dateLastSent = emailAndDatePair.Value; int daysBeforeResend = (dateLastSent.AddDays(resendableDays) - DateTime.Now).Days; string whenCanBeResentDescription; if (daysBeforeResend == 0) { whenCanBeResentDescription = String.Format("today at {0}", dateLastSent.ToShortTimeString()); } else if (daysBeforeResend == 1) { whenCanBeResentDescription = "tomorrow"; } else { whenCanBeResentDescription = String.Format("in {0} days", daysBeforeResend); } sb.AppendLine(String.Format("{0} (Can be resent {1}.)<br />", emailAndDatePair.Key, whenCanBeResentDescription)); } duplicateList.InnerHtml = sb.ToString(); } if (ownEmailSupplied) { LinkMePage.AddError(ValidationErrorMessages.INVITE_YOURSELF); } if (validEmails.Count > 0) { if (request != null) { donationWillBeMade.Visible = true; } invitesSentPanel.Visible = true; var sb = new StringBuilder(); foreach (string email in validEmails) { sb.AppendLine(email + "<br />"); } invitesSent.InnerHtml = sb.ToString(); } return(true); } return(false); } catch (DailyLimitException) { LinkMePage.AddError(ValidationErrorMessages.DAILY_LIMIT_EXCEEDED); return(false); } }