private void LoadControl() { const string method = "LoadControl"; bool doSendInvitation = (Request.Params[SendInvitationParameter] == "true"); Guid inviteeId = ParseUtil.ParseUserInputGuid(Request.Params[InviteeIdParameter], "invitee ID"); if (inviteeId == LoggedInMember.Id) { Controls.Add(GetInformationMessage(CannotAddSelfToFriends, true)); return; } var invitee = _membersQuery.GetMember(inviteeId); if (invitee == null) { Controls.Add(GetInformationMessage(CouldNotFindMember, true)); EventSource.Raise(Event.Error, method, string.Format("Tried to invite nonexistent member. inviteeId: {0}", inviteeId)); return; } var view = _memberViewsQuery.GetPersonalView(LoggedInMember.Id, invitee); if (view.ActualContactDegree == PersonalContactDegree.FirstDegree) { Controls.Add(GetInformationMessage(string.Format(AlreadyFriendsFormat, invitee.FullName), false)); return; } var invitation = _memberFriendsQuery.GetFriendInvitation(LoggedInMember.Id, invitee.Id); if (invitation != null && !_memberFriendsCommand.CanSendInvitation(invitation)) { Controls.Add(GetInformationMessage(GetSendingNotAllowedReason(invitee, invitation), false)); return; } if (view.CanAccess(PersonalVisibility.SendInvites)) { if (doSendInvitation) { Controls.Add(Send(invitee.Id)); } else { Controls.Add(GetAddToFriends(invitee)); } } else { Controls.Add(GetInformationMessage(NotAcceptingInvitations, 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); } }