Ejemplo n.º 1
0
        protected void rptRepresentativeInvitations_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var invitationId = new Guid((string)e.CommandArgument);
            var invitation   = _memberFriendsQuery.GetRepresentativeInvitation(invitationId);

            if (invitation == null)
            {
                LinkMePage.AddError(ValidationErrorMessages.INVALID_INVITATION);
                return;
            }

            var inviter = _membersQuery.GetMember(invitation.InviterId);

            switch (e.CommandName)
            {
            case "AcceptInvitation":
                try
                {
                    _memberFriendsCommand.AcceptInvitation(LoggedInMember.Id, invitation);
                    var successMsg = invitation.GetInvitationAcceptedHtml(inviter);
                    LinkMePage.AddConfirm(successMsg, false);
                }
                catch (UserException ex)
                {
                    LinkMePage.AddError(ex);
                }
                break;

            case "IgnoreInvitation":
                _memberFriendsCommand.RejectInvitation(invitation);
                LinkMePage.AddConfirm(string.Format(ValidationInfoMessages.INVITE_IGNORED, inviter.FullName.MakeNamePossessive()));
                break;
            }

            InitialiseInvitations(); // Re-initialise - just hiding items casuses bug 8772
        }
Ejemplo n.º 2
0
        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);
            }
        }
        protected void rptSavedResumeSearches_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var memberSearchId = new Guid(e.CommandArgument.ToString());
            var memberSearch   = _memberSearchesQuery.GetMemberSearch(memberSearchId);

            if (memberSearch == null)
            {
                switch (e.CommandName.ToUpper())
                {
                case "EXECUTE":
                    LinkMePage.AddError("The search you wanted to run no longer exists.");
                    break;

                case "CREATEEMAILALERT":
                    LinkMePage.AddError("The search for which you tried to create an Email Alert no longer exists. " +
                                        "Your Alert was not created.");
                    break;

                default:
                    break;
                }

                BindSavedResumeSearchesRepeater();
                return;
            }

            try
            {
                SearchHelper.EnsureEmployerIsJobPoster(LoggedInUserId.Value, memberSearch);
            }
            catch (UserException ex)
            {
                LinkMePage.AddError(ex.Message);
                return;
            }

            switch (e.CommandName.ToUpper())
            {
            case null:
                break;

            case "EXECUTE":
                var url = SearchRoutes.Saved.GenerateUrl(new { savedSearchId = memberSearch.Id });
                NavigationManager.Redirect(url);
                break;

            case "CREATEEMAILALERT":

                // Update it.

                _memberSearchAlertsCommand.UpdateMemberSearch(LoggedInUser, memberSearch, new Tuple <AlertType, bool>(AlertType.Email, true));
                BindSavedResumeSearchesRepeater();
                OnSavedResumeSearchAction(new SavedResumeSearchEventArgs("The search \"" + memberSearch.GetDisplayHtml() + "\" has been made into an email alert."));
                break;

            case "REMOVE":
                _memberSearchAlertsCommand.DeleteMemberSearch(LoggedInUser, memberSearch);
                BindSavedResumeSearchesRepeater();

                if (_items != null && _items.Count > 0)
                {
                    OnSavedResumeSearchAction(new SavedResumeSearchEventArgs("The search \"" + memberSearch.GetDisplayHtml() + "\" has been removed."));
                }
                break;

            default:
                break;
            }
        }