Esempio n. 1
0
    protected void ButtonAddMembership_Click(object sender, EventArgs e)
    {
        // TODO: Re-authorize?
        int    organizationId = Convert.ToInt32(dropOrganizations.SelectedValue);
        Person person         = Person.FromIdentity(Convert.ToInt32("" + Request["id"]));

        if (_authority.HasPermission(Permission.CanEditMemberships, organizationId, -1, Authorization.Flag.AnyGeography))
        {
            int      viewingPersonId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
            DateTime paidUntil       = DateTime.Now.AddYears(1);

            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipAdd,
                        "Membership in " + Organization.FromIdentity(organizationId).NameShort + " added manually.",
                        "Membership was added by " + Person.FromIdentity(viewingPersonId) + " (#" +
                        viewingPersonId.ToString() + ") to last until " + paidUntil.ToString("yyyy-MMM-dd") + ".");

            Membership.Create(person.PersonId, organizationId, paidUntil);
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.AddedMembership, viewingPersonId,
                                                        organizationId, person.GeographyId, person.PersonId, 0, string.Empty);

            ReadMembershipList();
            gridMemberships.DataBind();
            PopulateOrganizations();
        }
    }
Esempio n. 2
0
    protected void gridMemberships_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int membershipId = Convert.ToInt32(this.gridMemberships.DataKeys[e.Row.RowIndex].Value);

            Membership membership = Membership.FromIdentity(membershipId);

            // mark expired memberships with *
            Label      LabelExpiredFlag    = e.Row.FindControl("LabelExpiredFlag") as Label;
            LinkButton LinkButtonTerminate = e.Row.FindControl("LinkButtonTerminate") as LinkButton;
            LinkButton LinkButtonExtend    = e.Row.FindControl("LinkButtonExtend") as LinkButton;
            if (LabelExpiredFlag != null &&
                DateTime.Now.AddMinutes(10) > membership.DateTerminated &&
                membership.DateTerminated > new DateTime(1902, 01, 01))
            {
                LabelExpiredFlag.Text       = "*";
                LinkButtonTerminate.Enabled = false;
                LinkButtonTerminate.Text    = membership.DateTerminated.ToString("yyyy-MMM-dd");
            }

            //HACK: New functionality: Self service for members to extend and terminate
            // needs to be verified with organisations.

            // onlu PP and UP members are allowed to extend themselves and  terminate themselves
            if (!(membership.Organization.IsOrInherits(Organization.UPSEid) || membership.Organization.IsOrInherits(Organization.PPSEid)))
            {
                LinkButtonTerminate.Visible = false;
                LinkButtonExtend.Visible    = false;
            }
        }
    }
Esempio n. 3
0
    protected void GridMemberships_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // TODO: Re-authorize?

        int index           = Convert.ToInt32(e.CommandArgument);
        int viewingPersonId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
        int membershipId    = Convert.ToInt32(this.gridMemberships.DataKeys[index].Value);

        Membership  membership = Membership.FromIdentity(membershipId);
        BasicPerson person     = Person.FromIdentity(membership.PersonId);

        switch (e.CommandName)
        {
        case "Extend":
            if (membership.Expires.Year <= DateTime.Now.Year || membership.Active == false)
            {
                if (membership.Active == false && membership.Expires < DateTime.Now.AddYears(1))
                {
                    membership.Expires = DateTime.Now.AddYears(1);
                }
                else if (membership.Expires > DateTime.Now.AddYears(1))
                {
                    membership.Expires = membership.Expires.AddSeconds(1);
                }
                else
                {
                    membership.Expires = membership.Expires.AddYears(1);
                }

                PWLog.Write(Person.FromIdentity(viewingPersonId), PWLogItem.Person, person.Identity,
                            PWLogAction.MembershipRenewed,
                            "Membership in " + Organization.FromIdentity(membership.OrganizationId).NameShort +
                            " extended manually.",
                            "Membership was extended by " + Person.FromIdentity(viewingPersonId).Name + " (#" +
                            viewingPersonId.ToString() + ") to last until " +
                            membership.Expires.ToString("yyyy-MMM-dd") + ".");
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.PirateWeb, EventType.ExtendedMembership, viewingPersonId,
                                                            membership.OrganizationId, person.GeographyId, membership.PersonId,
                                                            membershipId, string.Empty);
            }
            ReadMembershipList();
            break;

        case "Terminate":
            if (membership.Active)
            {
                Membership.FromIdentity(membershipId).Terminate(EventSource.PirateWeb, Person.FromIdentity(viewingPersonId), "Membership in " + Organization.FromIdentity(membership.OrganizationId).NameShort + " removed manually.");
                ReadMembershipList();
                PopulateOrganizations();
                CheckStillVisible();
            }
            break;

        default:
            throw new InvalidOperationException("Not supported: Command \"" + e.CommandName + "\"");
        }

        gridMemberships.DataBind();
    }
Esempio n. 4
0
    protected void gridMemberships_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int membershipId = Convert.ToInt32(this.gridMemberships.DataKeys[e.Row.RowIndex].Value);

            Membership membership = Membership.FromIdentity(membershipId);

            // mark expired memberships with *
            Label      LabelExpiredFlag    = e.Row.FindControl("LabelExpiredFlag") as Label;
            LinkButton LinkButtonTerminate = e.Row.FindControl("LinkButtonTerminate") as LinkButton;
            if (LabelExpiredFlag != null &&
                DateTime.Now.AddMinutes(10) > membership.DateTerminated &&
                membership.DateTerminated > new DateTime(1902, 01, 01))
            {
                LabelExpiredFlag.Text       = "*";
                LinkButtonTerminate.Enabled = false;
                LinkButtonTerminate.Text    = membership.DateTerminated.ToString("yyyy-MMM-dd");
            }
        }
    }
Esempio n. 5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        bool   success       = false;
        string expectedHash1 = "";
        string expectedHash2 = "";
        Person person        = null;
        string redirectUrl   = string.Empty;

        int personId = 0;

        //New or old variant? MemberId indicates old variant with common date for all orgs.
        if (Int32.TryParse(Request.QueryString["MemberId"], out personId))
        {
            // Ok, at least we have  a valid person id.

            person = Person.FromIdentity(personId);

            DateTime    currentExpiry      = DateTime.MaxValue;
            DateTime    newExpiry          = DateTime.MinValue;
            Memberships memberships        = person.GetRecentMemberships(Membership.GracePeriod);
            string[]    mIds               = ("" + Request.QueryString["MID"]).Split(',');
            bool        membershipExists   = false;
            Membership  membershipToExtend = null;
            if (mIds.Length > 0)
            {
                memberships = new Memberships();
                foreach (string mId in mIds)
                {
                    try
                    {
                        Membership membership = Membership.FromIdentity(Convert.ToInt32(mId));
                        memberships.Add(membership);
                        //find earliest expiry in expiring orgs
                        if (membership.Expires < currentExpiry)
                        {
                            currentExpiry      = membership.Expires;
                            newExpiry          = currentExpiry.AddYears(1);
                            membershipExists   = true;
                            membershipToExtend = membership;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            // Get the new expiry from org 1 Organization.PPSEid

            bool isPpMember = false;
            bool isUPMember = false;

            foreach (Membership membership in person.GetRecentMemberships(Membership.GracePeriod))
            {
                if (membership.OrganizationId == Organization.PPSEid)
                {
                    isPpMember = true;
                }
                else if (membership.Organization.IsOrInherits(Organization.UPSEid))
                {
                    isUPMember = true;
                }
                if (membership.Expires < currentExpiry &&
                    (membership.Organization.IsOrInherits(Organization.UPSEid) ||
                     membership.OrganizationId == Organization.PPSEid))
                {
                    currentExpiry      = membership.Expires;
                    newExpiry          = currentExpiry.AddYears(1);
                    membershipExists   = true;
                    membershipToExtend = membership;
                }
            }


            if (membershipExists)
            {
                // The default is to renew all existing memberships. However, a person can also
                // request a transfer or to leave one specific organization.

                // This is built into the security token.

                string token1 = person.Name.Replace(" ", "-") + person.PasswordHash + "-" +
                                currentExpiry.Year.ToString();
                string token2           = person.PasswordHash + "-" + currentExpiry.Year.ToString();
                int    leaveOrgId       = 0;
                int    transferOldOrgId = 0;
                int    transferNewOrgId = 0;

                string leaveString    = Request.QueryString["Leave"];
                string transferString = Request.QueryString["Transfer"];

                if (!string.IsNullOrEmpty(leaveString))
                {
                    leaveOrgId = Int32.Parse(leaveString);
                    token1    += "-Leave" + leaveOrgId.ToString();
                    token2    += "-Leave" + leaveOrgId.ToString();
                }

                if (!string.IsNullOrEmpty(transferString))
                {
                    string[] tokens = transferString.Split(',');
                    transferOldOrgId = Int32.Parse(tokens[0]);
                    transferNewOrgId = Int32.Parse(tokens[1]);

                    token1 += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                    token2 += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                }

                expectedHash1 = SHA1.Hash(token1).Replace(" ", "").Substring(0, 8);
                expectedHash2 = SHA1.Hash(token2).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedHash1 || Request.QueryString["SecHash"] == expectedHash2)
                {
                    success = true;

                    this.LabelExpires.Text = newExpiry.ToString("yyyy-MM-dd");

                    if (leaveOrgId > 0)
                    {
                        Membership membership = person.GetRecentMembership(Membership.GracePeriod, leaveOrgId);

                        // Might have been terminated already
                        if (membership != null && membership.Active)
                        {
                            //Terminate logs and creates appropriate events
                            membership.Terminate(EventSource.SignupPage, person,
                                                 "Membership in " + membership.Organization.NameShort +
                                                 " was terminated while renewing.");
                        }
                        this.PanelLeft.Visible             = true;
                        this.LiteralLeftOrganizations.Text = "<b>" +
                                                             Server.HtmlEncode(
                            Organization.FromIdentity(leaveOrgId).Name) + "</b>";
                    }

                    if (transferOldOrgId > 0)
                    {
                        Membership oldMembership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        // Might have been terminated already
                        if (oldMembership != null)
                        {
                            Membership newMembership = Membership.Create(person.Identity, transferNewOrgId,
                                                                         oldMembership.Expires);

                            //Terminate logs and creates appropriate events
                            oldMembership.Terminate(EventSource.SignupPage, person,
                                                    "Membership in " + oldMembership.Organization.NameShort +
                                                    " was transferred to " + newMembership.Organization.NameShort +
                                                    " while renewing.");
                        }
                        this.LabelTransferOldOrganization.Text = Organization.FromIdentity(transferOldOrgId).Name;
                        this.LabelTransferNewOrganization.Text = Organization.FromIdentity(transferNewOrgId).Name;
                        this.PanelTransferred.Visible          = true;
                    }

                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                EventType.ReceivedMembershipPayment,
                                                                person.Identity, membershipToExtend.OrganizationId,
                                                                person.Geography.Identity, person.Identity, 0,
                                                                Request.UserHostAddress);

                    string orgList = string.Empty;

                    foreach (Membership membership in person.GetRecentMemberships(Membership.GracePeriod))
                    {
                        if (membership.OrganizationId != leaveOrgId)
                        {
                            if ((isPpMember && membership.OrganizationId == Organization.PPSEid) ||
                                (isUPMember && membership.Organization.IsOrInherits(Organization.UPSEid)) ||
                                (memberships.Contains(membership)))
                            {
                                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                            "Membership in " + membership.Organization.NameShort + " renewed.",
                                            "Membership was renewed from IP " + Request.UserHostAddress + ".");
                                orgList += ", <b>" + Server.HtmlEncode(membership.Organization.Name) + "</b>";
                            }
                        }
                    }

                    orgList = orgList.Substring(2);
                    this.LiteralRenewedOrganizations.Text = orgList;
                }
            }
            else
            {
                // There were no existing memberships. Create new ones. This is the PPSE path, so create a new membership for just PPSE.

                // Verify security token.

                string tokenBase = person.Name.Replace(" ", "-") + person.PasswordHash + "-" +
                                   DateTime.Today.Year.ToString();
                string expectedSecurityHash = SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedSecurityHash)
                {
                    Membership.Create(person, Organization.PPSE, DateTime.Today.AddYears(1));
                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                EventType.ReceivedMembershipPayment,
                                                                person.Identity, Organization.PPSEid,
                                                                person.Geography.Identity, person.Identity, 0,
                                                                Request.UserHostAddress);
                    PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                "A renewed membership in " + Organization.PPSE.NameShort + " was signed up.",
                                "Membership was created from IP " + Request.UserHostAddress + ".");
                    success = true;
                }
            }
        }

        string errorType = "";

        try
        {
            // This is the new path - we expect all renewals from Dec 14, 2010 and onward to follow this. Delete the old path (with "MemberId") some time February 2011.

            if (Int32.TryParse(Request.QueryString["PersonId"], out personId))
            {
                // Ok, at least we have  a valid person id.

                person = Person.FromIdentity(personId);

                string     transferString   = Request.QueryString["Transfer"];
                Membership membership       = null;
                DateTime   newExpiry        = DateTime.MinValue;;
                int        transferOldOrgId = 0;
                int        transferNewOrgId = 0;
                try
                {
                    if (Request.QueryString["MembershipId"] != null)
                    {
                        membership = Membership.FromIdentity(Int32.Parse(Request.QueryString["MembershipId"]));
                        newExpiry  = membership.Expires;

                        //do not mess with lifetime memberships (100 years)
                        if (newExpiry < DateTime.Today.AddYears(10))
                        {
                            newExpiry = newExpiry.AddYears(1);
                            if (newExpiry > DateTime.Now.AddYears(1))
                            {
                                newExpiry = DateTime.Now.AddYears(1).AddDays(1);
                            }
                        }

                        if (membership.OrganizationId == Organization.PPSEid)
                        {
                            redirectUrl = "http://www.piratpartiet.se/fornyelse"; // HACK, have an org parameter for this later
                        }

                        if (membership.PersonId != personId)
                        {
                            throw new ArgumentException("Mismatching membership and person");
                        }
                    }
                    else if (Request.QueryString["Transfer"] != null)
                    {
                        if (!string.IsNullOrEmpty(transferString))
                        {
                            string[] tokens = transferString.Split(',');
                            transferOldOrgId = Int32.Parse(tokens[0]);
                        }
                        membership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        if (membership == null)
                        {
                            throw new ArgumentException("Can't find membership");
                        }
                        //do not mess with lifetime memberships (100 years)
                        if (membership.Expires < DateTime.Today.AddYears(10))
                        {
                            if (membership.Expires > DateTime.Today.AddYears(1))
                            {
                                newExpiry = membership.Expires;
                            }
                            else
                            {
                                newExpiry = DateTime.Today.AddYears(1);
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("No MembershipId given");
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("No Membership found: " + ex.Message, ex);
                }

                if (!membership.Active)
                {
                    if (membership.DateTerminated.AddDays(Membership.GracePeriod) < DateTime.Today)
                    {
                        throw new ArgumentException("Membership has expired beyond recovery");
                    }

                    newExpiry = DateTime.Today.AddYears(1);

                    if (membership.OrganizationId == Organization.PPSEid)
                    {
                        redirectUrl = "http://www.piratpartiet.se/fornyelse"; // HACK, have an org parameter for this later
                    }
                }


                string tokenBase = person.PasswordHash + "-" + membership.Identity.ToString() + "-" +
                                   membership.Expires.Year.ToString();


                if (!string.IsNullOrEmpty(transferString))
                {
                    string[] tokens = transferString.Split(',');
                    transferOldOrgId = Int32.Parse(tokens[0]);
                    transferNewOrgId = Int32.Parse(tokens[1]);

                    tokenBase += "-Transfer" + transferOldOrgId.ToString() + "/" + transferNewOrgId.ToString();
                }

                if (transferOldOrgId != 0 && transferOldOrgId != membership.OrganizationId)
                {
                    throw new ArgumentException("Invalid Transfer Order");
                }

                string expectedHash = SHA1.Hash(tokenBase).Replace(" ", "").Substring(0, 8);

                if (Request.QueryString["SecHash"] == expectedHash)
                {
                    success = true;

                    this.LabelExpires.Text = newExpiry.ToString("yyyy-MM-dd");
                    int orgMembershipToExtend = membership.OrganizationId;


                    if (transferOldOrgId > 0)
                    {
                        Membership oldMembership = person.GetRecentMembership(Membership.GracePeriod, transferOldOrgId);
                        Membership newMembership = membership;
                        // Might have been terminated already
                        if (oldMembership != null)
                        {
                            newMembership = Membership.Create(person.Identity, transferNewOrgId, oldMembership.Expires);

                            //Terminate logs and creates appropriate events
                            oldMembership.Terminate(EventSource.SignupPage, person,
                                                    "Membership in " + oldMembership.Organization.NameShort +
                                                    " was transferred to " + newMembership.Organization.NameShort +
                                                    " while renewing.");

                            membership = newMembership;
                        }
                        this.LabelTransferOldOrganization.Text = Organization.FromIdentity(transferOldOrgId).Name;
                        this.LabelTransferNewOrganization.Text = Organization.FromIdentity(transferNewOrgId).Name;
                        this.PanelTransferred.Visible          = true;

                        orgMembershipToExtend = transferNewOrgId;
                    }

                    Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage,
                                                                EventType.ReceivedMembershipPayment,
                                                                person.Identity, orgMembershipToExtend,
                                                                person.Geography.Identity, person.Identity, 0,
                                                                Request.UserHostAddress);

                    PWLog.Write(person.Identity, PWLogItem.Person, person.Identity, PWLogAction.MembershipRenewed,
                                "Membership in " + membership.Organization.NameShort + " renewed.",
                                "Membership was renewed from IP " + Request.UserHostAddress + ".");

                    this.LiteralRenewedOrganizations.Text = Organization.FromIdentity(orgMembershipToExtend).Name;
                }
            }
        }
        catch (ArgumentException e2)
        {
            // Something failed parsing the parameters. Do not renew.
            errorType = e2.Message;
        }


        if (!success)
        {
            // Send a couple mails
            PWLog.Write(person.Identity, PWLogItem.Person, person.Identity, PWLogAction.Failure, "Tech failure on membership renewal: " + Request.RawUrl + " Errormessage:" + errorType, "Renewal attempt from from IP " + Request.UserHostAddress + ".");

            person.SendNotice("Vill du f\xF6rnya?",
                              "Alldeles nyss f\xF6rs\xF6kte n\xE5gon, troligtvis du, f\xF6rnya ditt medlemskap i Piratpartiet " +
                              "och/eller Ung Pirat. Det misslyckades p\xE5 grund av en felaktig s\xE4kerhetskod.\r\n\r\n" +
                              "Det kan bero p\xE5 ett antal anledningar, men f\xF6r att vara s\xE4ker p\xE5 att det inte \xE4r " +
                              "on\xF6" + "diga tekniska fel som hindrar dig fr\xE5n att forts\xE4tta vara medlem, s\xE5 kan vi ocks\xE5 f\xF6rnya " +
                              "ditt medlemskap manuellt.\r\n\r\nAllt som kr\xE4vs \xE4r att du svarar JA p\xE5 det h\xE4r brevet och " +
                              "skickar tillbaka det till Medlemsservice (avs\xE4ndaren).\r\n\r\n" +
                              "Vill du f\xF6rnya ditt eller dina befintliga medlemskap i Piratpartiet och/eller Ung Pirat " +
                              "f\xF6r ett \xE5r till?\r\n\r\n", Organization.PPSEid);
            Person.FromIdentity(1).SendNotice("Misslyckad f\xF6rnyelse",
                                              person.Name + " (#" + person.Identity.ToString() + ") f\xF6rs\xF6kte f\xF6rnya medlemskapet. Det misslyckades:" + errorType +
                                              "Ett mail har skickats ut.\r\n", Organization.PPSEid);
        }
        else
        {
            this.PanelSuccess.Visible = success;
            this.PanelFail.Visible    = !success;

            if (!String.IsNullOrEmpty(redirectUrl))
            {
                Response.Redirect(redirectUrl);
            }
        }
    }
Esempio n. 6
0
    private void CreateMember()
    {
        // If youthOrg is true, then the person opted for youth league membership.

        bool youthOrgSelected = this.RadioYouthLeague.Checked || this.RadioYouthLeagueOnly.Checked == true;

        PaymentCode paymentCode = null;

        /*
         * // Payments disabled
         *
         * if (!youthOrgSelected)
         * {
         *  paymentCode = PaymentCode.FromCode(this.TextPaymentCode.Text);
         * }*/

        string name        = this.TextName.Text;
        string password    = ViewState["pw"] as string;
        string email       = this.TextEmail.Text.Replace(",", "."); // for some reason 1 in 500 mistypes this
        string phone       = this.TextPhone.Text;
        string street      = this.TextStreet.Text;
        string postal      = this.TextPostal.Text;
        string city        = this.TextCity.Text;
        string countryCode = this.DropCountries.SelectedValue;

        int birthDay   = Convert.ToInt32(this.TextBirthDay.Text);
        int birthMonth = Convert.ToInt32(this.DropBirthMonths.SelectedValue);
        int birthYear  = Convert.ToInt32(this.TextBirthYear.Text);

        DateTime     birthdate = new DateTime(birthYear, birthMonth, birthDay);
        PersonGender gender    = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue);

        // This will stop the Create to be called twice even if doubleclick
        SessionMemberDuplicateStop = DateTime.Now;;

        // We are ready to create the new person.

        Person person = Person.Create(name, email, password, phone, street, postal, city, countryCode, birthdate, gender);

        // The creation resolves the appropriate geography, so we can determine the correct
        // organization to join the person to.

        // In some cases PostalCode does not indicate the geography uniquely
        if (DropDownKommun.SelectedIndex >= 0)
        {
            person.Geography = Geography.FromIdentity(int.Parse(DropDownKommun.SelectedValue));
        }

        // Add memberships, as appropriate.

        Organization youthOrg = null;

        this.LabelMemberOfOrganizations.Text = string.Empty;

        if (youthOrgSelected)
        {
            try
            {
                youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, Organization.UPDKid);
            }
            catch (ArgumentException ex)
            {
                //didnt find any, Does the org itself accept members?
                youthOrg = Organization.FromIdentity(Organization.UPDKid);
                if (!youthOrg.AcceptsMembers)
                {
                    throw ex; //rethrow
                }
            }
            Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(1));
            newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now);
            this.LabelMemberOfOrganizations.Text = "<br><b>" + Server.HtmlEncode(youthOrg.Name) + "</b> og <br/>";
        }

        if (!this.RadioYouthLeagueOnly.Checked)
        {
            person.AddMembership(Organization.PPDKid, DateTime.Now.AddYears(1));
            this.LabelMemberOfOrganizations.Text += "<b>Piratpartiet</b>";
        }

        // Create events.

        if (RadioYouthLeague.Checked)
        {
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                        person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + " " + Organization.PPDKid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organization " + youthOrg.NameShort + " and Piratpartiet DK.", "The self-signup came from IP address " + Request.UserHostAddress + ".");
        }
        else if (RadioYouthLeagueOnly.Checked)
        {
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                        person.Identity, youthOrg.Identity, person.GeographyId, person.Identity, 0, youthOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined organizations " + youthOrg.NameShort, "The self-signup came from IP address " + Request.UserHostAddress + ".");
        }
        else
        {
            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                        person.Identity, Organization.PPDKid, person.GeographyId, person.Identity, 0, Organization.PPDKid.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "New member joined Piratpartiet DK.", "The self-signup came from IP address " + Request.UserHostAddress + ".");
        }

        // Claim the payment.

        if (paymentCode != null)
        {
            paymentCode.Claim(person);
        }

        // If activity level was not passive (activist or officer), then register as activist.

        if (!this.RadioActivityPassive.Checked)
        {
            person.CreateActivist(false, false);

            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewActivist,
                                                        person.Identity, Organization.PPDKid, person.GeographyId, person.Identity, 0, string.Empty);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Joined as activist.", string.Empty);
        }

        // If activity level was officer, register as officer volunteer.

        if (this.RadioActivityOfficer.Checked)
        {
            int[] chairman = Authorization.PersonsWithRoleInOrg(RoleType.OrganizationChairman, Organization.PPFIid, false);
            if (chairman.Length > 0)
            {
                Person defaultOwner = Person.FromIdentity(chairman[0]);

                Volunteer volunteer = Volunteer.Create(person, defaultOwner); // RF owns new volunteers

                //Autoassign will try to assign to ElectoralCircuit lead or
                //if not possible, to its parent org lead, or if not possible to defaultOwner
                //TODO:Ugly hack sweden hardcoded (30)
                volunteer.AutoAssign(person.Geography, Organization.PPDKid, defaultOwner, Geography.SwedenId);

                volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalLead);
                volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalDeputy);
                volunteer.AddRole(Organization.PPDKid, person.GeographyId, RoleType.LocalAdmin);

                string textParameter = person.Name.Replace("|", "") + "|" +
                                       person.Phone.Replace("|", "") +
                                       "|Yes|KL1 KL2 KLA";

                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPDKid, person.GeographyId, 0, 0, textParameter);
                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty);
            }
        }
    }
Esempio n. 7
0
    protected void ButtonExpiringList_Click(object sender, EventArgs e)
    {
        Organization selectedOrg = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue));
        int          days        = 0;

        if (!int.TryParse(this.ExpiryDays.Text, out days))
        {
            this.ExpiryDays.Text = "Error";
            return;
        }

        DateTime lowerlimit = DateTime.Today;
        DateTime upperlimit = DateTime.Today;

        if (days < 0)
        {
            lowerlimit = DateTime.Today.AddDays(days);
        }
        else
        {
            upperlimit = DateTime.Today.AddDays(days + 1);
        }

        lock (membershipCacheLock)
        {
            if (membershipCache == null)
            {
                membershipCache = new Dictionary <int, OrgMembershipCacheEntry>();
            }

            //Tidy up cache to release memory
            if (membershipCache.Count > 0)
            {
                int[] keys = new int[membershipCache.Count];
                membershipCache.Keys.CopyTo(keys, 0);
                foreach (int orgid in keys)
                {
                    if (DateTime.Now > membershipCache[orgid].membershipCacheTime.AddMinutes(5))
                    {
                        membershipCache.Remove(orgid);
                    }
                }
            }

            //load cache
            if (!membershipCache.ContainsKey(selectedOrg.Identity) ||
                DateTime.Now > membershipCache[selectedOrg.Identity].membershipCacheTime.AddMinutes(5))
            {
                RebuildMembershipCacheForOrg(selectedOrg.Identity);
            }
        }



        People results = GetResults();

        results = results.Filter(delegate(Person p)
        {
            if (membershipCache.ContainsKey(selectedOrg.Identity))
            {
                OrgMembershipCacheEntry msc = membershipCache[selectedOrg.Identity];
                if (msc.memberships.ContainsKey(p.Identity))
                {
                    Activizr.Logic.Pirates.Membership m = msc.memberships[p.Identity];
                    if (m.Expires >= lowerlimit && m.Expires < upperlimit)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        });

        PersonList.ShowExpiry = true;
        PersonList.ListedOrg  = selectedOrg.Identity;

        PersonList.PersonList     = results;
        LabelExpiryHeader.Visible = true;
    }
Esempio n. 8
0
    private void CreateMember()
    {
        bool youthOrgSelected = this.cbYouthOnly.Checked;
        bool partyOrgSelected = this.cbParty.Checked;
        bool localOrgSelected = this.cbPartyAndLocal.Checked && partyOrgSelected;

        int partyOrgID = Organization.PPFIid;
        int youthOrgID = Organization.UPFIid;//Not yet defined

        PaymentCode paymentCode = null;

        /*
         * // Payments disabled
         *
         * if (!youthOrgSelected)
         * {
         *  paymentCode = PaymentCode.FromCode(this.TextPaymentCode.Text);
         * }*/

        string name        = this.TextName.Text;
        string password    = ViewState["pw"] as string;
        string email       = this.TextEmail.Text.Replace(",", "."); // for some reason 1 in 500 mistypes this
        string phone       = this.TextPhone.Text;
        string street      = this.TextStreet.Text;
        string postal      = this.TextPostal.Text;
        string city        = this.TextCity.Text;
        string countryCode = this.DropCountries.SelectedValue;

        int birthDay   = Convert.ToInt32(this.TextBirthDay.Text);
        int birthMonth = Convert.ToInt32(this.DropBirthMonths.SelectedValue);
        int birthYear  = Convert.ToInt32(this.TextBirthYear.Text);

        DateTime     birthdate = new DateTime(birthYear, birthMonth, birthDay);
        PersonGender gender    = (PersonGender)Enum.Parse(typeof(PersonGender), this.DropGenders.SelectedValue);

        // This will stop the Create to be called twice even if doubleclick
        SessionMemberDuplicateStop = DateTime.Now;;

        // We are ready to create the new person.
        People people = People.FromEmail(email); // already in db?
        Person person = null;

        foreach (Person p in people)
        {
            if (p.Birthdate == birthdate)
            {
                person = p;
            }
        }

        if (person != null)
        {
            person.TempPasswordHash = person.PasswordHash;//save it, but dont trash the existing one
            Authentication.RequestMembershipConfirmation(person, "https://pirateweb.net/Pages/Public/FI/People/ConfirmMembership.aspx?member={0}&ticket={1}");
        }
        else
        {
            person = Person.Create(name, email, Formatting.GeneratePassword(9), phone, street, postal, city, countryCode, birthdate, gender);
            person.SetPassword(password);                       //set the given password
            person.TempPasswordHash = person.PasswordHash;      //save it.
            person.SetPassword(Formatting.GeneratePassword(9)); //Generate a random one.
            Authentication.RequestMembershipConfirmation(person, "https://pirateweb.net/Pages/Public/FI/People/ConfirmMembership.aspx?member={0}&ticket={1}");
        }



        // The creation resolves the appropriate geography, so we can determine the correct
        // organization to join the person to.

        // In some cases PostalCode does not indicate the geography uniquely
        if (DropDownKommun.SelectedIndex >= 0)
        {
            person.Geography = Geography.FromIdentity(int.Parse(DropDownKommun.SelectedValue));
        }

        if (person.GeographyId == 0)
        {
            person.Geography = Geography.FromIdentity(Geography.FinlandId);
        }

        // Add memberships, as appropriate.

        Organization youthOrg      = null;
        Organization localPartyOrg = null;
        Organization partyOrg      = null;

        this.LabelMemberOfOrganizations.Text = string.Empty;

        if (youthOrgSelected)
        {
            try
            {
                youthOrg = Organizations.GetMostLocalOrganization(person.GeographyId, youthOrgID);
            }
            catch (ArgumentException ex)
            {
                //didnt find any, Does the org itself accept members?
                youthOrg = Organization.FromIdentity(youthOrgID);
                if (!youthOrg.AcceptsMembers)
                {
                    throw ex; //rethrow
                }
            }
            this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(youthOrg.Name) + "</b>, <br/>";
            if (!person.MemberOf(youthOrg.Identity))
            {
                Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(youthOrg.Identity, DateTime.Now.AddYears(100));
                newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now);
            }
            else
            {
                youthOrg = null;
            }
        }

        bool wasPartyMember = false;

        if (localOrgSelected)
        {
            try
            {
                // localPartyOrg = Organizations.GetMostLocalOrganization(person.GeographyId, partyOrgID);
                localPartyOrg = Organization.FromIdentity(Convert.ToInt32(DropDownListSubOrg.SelectedValue));
                this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(localPartyOrg.Name) + "</b>, <br/>";

                if (!person.MemberOf(localPartyOrg.Identity))
                {
                    Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(localPartyOrg.Identity, DateTime.Now.AddYears(100));
                    newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now);
                }
                else
                {
                    localPartyOrg = null;
                }
            }
            catch
            {
                //Asked for local org but didnt give enoght data
            }
        }

        if (partyOrgSelected && (wasPartyMember == false))
        {
            if (!person.MemberOf(partyOrgID))
            {
                Activizr.Logic.Pirates.Membership newMembership = person.AddMembership(partyOrgID, DateTime.Now.AddYears(100));
                newMembership.SetPaymentStatus(MembershipPaymentStatus.NewlyRegistered, DateTime.Now);
                partyOrg = Organization.FromIdentity(partyOrgID);
                this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(partyOrg.Name) + "</b>, <br/>";
            }
            else
            {
                partyOrg = Organization.FromIdentity(partyOrgID);
                this.LabelMemberOfOrganizations.Text += "<br><b>" + Server.HtmlEncode(partyOrg.Name) + "</b>, <br/>";
                partyOrg = null;
            }
        }

        // Create events.

        if (localPartyOrg != null || youthOrg != null || partyOrg != null)
        {
            if (localPartyOrg != null)
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                            person.Identity, localPartyOrg.Identity, person.GeographyId, person.Identity,
                                                            0, localPartyOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            }

            if (youthOrg != null)
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                            person.Identity, youthOrg.Identity, person.GeographyId, person.Identity,
                                                            0, youthOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            }

            if (partyOrg != null)
            {
                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.AddedMember,
                                                            person.Identity, partyOrg.Identity, person.GeographyId, person.Identity,
                                                            0, partyOrg.Identity.ToString() + "," + Request.UserHostAddress + "," + this.LabelReferrer.Text);
            }

            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd,
                        "New member joined organization " +
                        (youthOrg != null ? youthOrg.NameShort + " " : "") +
                        (localPartyOrg != null ? localPartyOrg.NameShort + " " : "") +
                        (partyOrg != null ? partyOrg.NameShort : ""),
                        "The self-signup came from IP address " + Request.UserHostAddress + ".");
        }


        // Claim the payment.

        if (paymentCode != null)
        {
            paymentCode.Claim(person);
        }

        // If activity level was not passive (activist or officer), then register as activist.

        if (!this.RadioActivityPassive.Checked)
        {
            person.CreateActivist(false, false);

            Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewActivist,
                                                        person.Identity, partyOrgID, person.GeographyId, person.Identity, 0, string.Empty);
            PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Joined as activist.", string.Empty);
        }

        // If activity level was officer, register as officer volunteer.

        if (this.RadioActivityOfficer.Checked)
        {
            int[] chairman = Authorization.PersonsWithRoleInOrg(RoleType.OrganizationChairman, Organization.PPFIid, false);
            if (chairman.Length > 0)
            {
                Person defaultOwner = Person.FromIdentity(chairman[0]);

                Volunteer volunteer = Volunteer.Create(person, defaultOwner); // RF owns new volunteers

                //Autoassign will try to assign to ElectoralCircuit lead or
                //if not possible, to its parent org lead, or if not possible to defaultOwner
                volunteer.AutoAssign(person.Geography, Organization.PPFIid, defaultOwner, Geography.FinlandId);

                volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalLead);
                volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalDeputy);
                volunteer.AddRole(Organization.PPFIid, person.GeographyId, RoleType.LocalAdmin);

                string textParameter = person.Name.Replace("|", "") + "|" +
                                       person.Phone.Replace("|", "") +
                                       "|Yes|KL1 KL2 KLA";

                Activizr.Logic.Support.PWEvents.CreateEvent(EventSource.SignupPage, EventType.NewVolunteer, 0, Organization.PPFIid, person.GeographyId, 0, 0, textParameter);
                PWLog.Write(PWLogItem.Person, person.Identity, PWLogAction.MemberAdd, "Volunteered for local officership.", string.Empty);
            }
        }
    }
Esempio n. 9
0
    protected void ButtonExpiringList_Click(object sender, EventArgs e)
    {
        Organization selectedOrg = Organization.FromIdentity(Convert.ToInt32(this.DropOrganizations.SelectedValue));
        DateTime     lowerlimit  = DateTime.Today;
        DateTime     upperlimit  = DateTime.Today;

        int days = 0;

        if (!int.TryParse(this.ExpiryDays.Text, out days))
        {
            this.ExpiryDays.Text = "Error";
            return;
        }

        upperlimit = DateTime.Today.AddDays(Math.Abs(days) + 1);

        days = 0;
        if (!int.TryParse(this.SinceDays.Text, out days))
        {
            this.SinceDays.Text = "Error";
        }

        days = Math.Abs(days);
        if (days > Activizr.Logic.Pirates.Membership.GracePeriod)
        {
            this.SinceDays.Text = "" + Activizr.Logic.Pirates.Membership.GracePeriod;
            days = Activizr.Logic.Pirates.Membership.GracePeriod;
        }
        lowerlimit = DateTime.Today.AddDays(-Math.Abs(days));

        lock (membershipCacheLock)
        {
            if (membershipCache == null)
            {
                membershipCache = new Dictionary <int, OrgMembershipCacheEntry>();
            }

            //Tidy up cache to release memory
            if (membershipCache.Count > 0)
            {
                int[] keys = new int[membershipCache.Count];
                membershipCache.Keys.CopyTo(keys, 0);
                foreach (int orgid in keys)
                {
                    if (DateTime.Now > membershipCache[orgid].membershipCacheTime.AddMinutes(5))
                    {
                        membershipCache.Remove(orgid);
                    }
                }
            }

            //load cache
            if (!membershipCache.ContainsKey(selectedOrg.Identity) ||
                DateTime.Now > membershipCache[selectedOrg.Identity].membershipCacheTime.AddMinutes(5))
            {
                RebuildMembershipCacheForOrg(selectedOrg.Identity);
            }
        }



        People results = GetResults(true, Activizr.Logic.Pirates.Membership.GracePeriod);

        lock (membershipCacheLock)
        {
            results = results.Filter(delegate(Person p)
            {
                if (membershipCache.ContainsKey(selectedOrg.Identity))
                {
                    OrgMembershipCacheEntry msc = membershipCache[selectedOrg.Identity];
                    if (msc.memberships.ContainsKey(p.Identity))
                    {
                        Activizr.Logic.Pirates.Membership m = msc.memberships[p.Identity];
                        //expired within search Period AND was not prematurely terminated
                        if (m.Expires >= lowerlimit && m.Expires < upperlimit &&
                            (m.DateTerminated < m.MemberSince || m.DateTerminated.AddDays(1) > m.Expires))
                        {
                            return(true);
                        }
                    }
                }
                return(false);
            });
        }

        PersonList.ShowExpiry = true;
        PersonList.ListedOrg  = selectedOrg.Identity;
        if (_authority.HasPermission(Permission.CanEditMemberships, selectedOrg.Identity, Convert.ToInt32(DropGeographies.SelectedValue), Authorization.Flag.Default))
        {
            PersonList.ShowStatus = true;
        }

        LabelExpiryHeader.Visible = true;
        PersonList.PersonList     = results;
    }
Esempio n. 10
0
    protected void ButtonLookup_Click(object sender, EventArgs e)
    {
        string url = this.TextForumUrl.Text;

        Regex re      = new Regex(@"t=(?<trheadid>\d+)");
        int   topicId = 0;

        Int32.TryParse(re.Match(url).Groups["trheadid"].Value, out topicId);

        if (topicId == 0)
        {
            LiteralResults.Text = "No valid thread Id recognized";
            return;
        }

        DateTime startdate = DateTime.Today;

        if (TextBoxDate.Text.Trim() != "")
        {
            DateTime.TryParse(TextBoxDate.Text, out startdate);
        }
        else
        {
            TextBoxDate.Text = startdate.ToString("yyyy-MM-dd");
        }

        Activizr.Logic.Special.Sweden.IForumDatabase forumDb = Activizr.Logic.Special.Sweden.SwedishForumDatabaseVBulletin.GetDatabase();

        int pollId = forumDb.GetPollIdFromTopicId(topicId);

        Boolean pollStillOpen             = false;
        Dictionary <string, People> votes = new Dictionary <string, People>();


        try
        {
            votes = forumDb.GetPollVotes(pollId);
        }
        catch (ArgumentOutOfRangeException)
        {
            pollStillOpen = true;
        }

        StringBuilder resultSB = new StringBuilder();

        if (pollStillOpen)
        {
            resultSB.Append("Sorry, that poll seems to be still open for voting.");
        }
        else
        {
            People allVoters = new People();

            int invalidVotes   = 0;
            int validVoters    = 0;
            int dateFailVoters = 0;

            foreach (People people in votes.Values)
            {
                foreach (Person person in people)
                {
                    if (person == null)
                    {
                        invalidVotes++;
                    }
                }
                allVoters = People.LogicalOr(allVoters, people);
            }



            foreach (Person person in allVoters)
            {
                if (person == null)
                {
                }
                else
                {
                    Membership memberSince = null;

                    Memberships memberships = person.GetMemberships(true);

                    bool membershipFound = false;

                    foreach (Membership membership in memberships)
                    {
                        if (membership.OrganizationId == Organization.PPSEid)
                        {
                            // If was menber two months ago, remember that startdate, not the one for the current membership.
                            // (to handle delayed renewals)
                            if (membership.Active == false &&
                                membership.DateTerminated > startdate.AddMonths(-2) &&
                                membership.MemberSince <= startdate.AddMonths(-2))
                            {
                                if (memberSince == null)
                                {
                                    memberSince = membership;
                                }

                                if (membership.Active == false &&
                                    membership.DateTerminated >= startdate &&
                                    membership.MemberSince <= startdate)
                                {
                                    membershipFound = true; //must be member at startdate
                                }
                            }
                            else if (membership.Active == false &&
                                     membership.DateTerminated >= startdate &&
                                     membership.MemberSince <= startdate)
                            {
                                membershipFound = true; //must be member at startdate
                                if (memberSince == null)
                                {
                                    memberSince = membership;
                                }
                            }
                            else if (membership.Active == true)
                            {
                                if (memberSince == null)
                                {
                                    memberSince = membership;
                                }

                                membershipFound = true; //must be member now
                            }
                        }
                    }
                    if (membershipFound)
                    {
                        if (memberSince.MemberSince.Date.AddMonths(2) > startdate)
                        {
                            resultSB.Append("Medlem #" + person.Identity + ", " + Server.HtmlEncode(person.Geography.Name) +
                                            ", medlem sedan " + memberSince.MemberSince.ToString("yyyy-MM-dd") + " (mindre &auml;n stadgad tid f&ouml;r r&ouml;str&auml;tt)<br/>");
                            dateFailVoters++;
                        }
                        else
                        {
                            resultSB.Append("Medlem #" + person.Identity + ", " + Server.HtmlEncode(person.Geography.Name) +
                                            ", medlem sedan " + memberSince.MemberSince.ToString("yyyy-MM-dd") + "<br/>");
                            validVoters++;
                        }
                    }
                    else
                    {
                        if (memberSince != null)
                        {
                            resultSB.Append("Medlem #" + person.Identity + " har ett nyligen utg&aring;nget medlemskap (" + memberSince.DateTerminated.ToString("yyyy-MM-dd") + "), r&auml;kna bort fr&aring;n antalet ovan.<br/>");
                        }
                        else
                        {
                            resultSB.Append("Medlem #" + person.Identity + " har ett nyligen utg&aring;nget medlemskap, r&auml;kna bort fr&aring;n antalet ovan.<br/>");
                        }
                        dateFailVoters++;
                    }
                }
            }

            if (invalidVotes > 0)
            {
                resultSB.Insert(0, invalidVotes.ToString() + " r&ouml;ster med ok&auml;nt medlemskap<br/><br/>");
            }
            resultSB.Insert(0, validVoters.ToString() + " r&ouml;ster med giltiga medlemskap:<br/><br/>");

            resultSB.Insert(0, "[h3]R&ouml;stl&auml;ngd[/h3]<br>");

            if (true || WSGeographyTreeDropDown1.SelectedGeographyId != Geography.RootIdentity)
            {
                int selectedGeo = WSGeographyTreeDropDown1.SelectedGeographyId;
                resultSB.Append("<br/>R&ouml;ster fr&aring;n geografier:<br/>");
                resultSB.Append("Vald (giltig) geografi: " + WSGeographyTreeDropDown1.SelectedGeography.Name + "<br/>");

                foreach (string voteAlternative in votes.Keys)
                {
                    resultSB.Append(Server.HtmlEncode(voteAlternative) + ": ");
                    Dictionary <string, int> geoResult = new Dictionary <string, int>();
                    geoResult["Korrekt"]           = 0;
                    geoResult["Annan"]             = 0;
                    geoResult["Under 2 m&aring;n"] = 0;
                    geoResult["Ej medlem"]         = 0;
                    geoResult["Totalt"]            = 0;

                    foreach (Person person in votes[voteAlternative])
                    {
                        if (person == null)
                        {
                            continue;
                        }

                        DateTime memberSince = DateTime.MinValue;

                        Memberships memberships     = person.GetMemberships(true);
                        bool        membershipFound = false;

                        foreach (Membership membership in memberships)
                        {
                            if (membership.OrganizationId == Organization.PPSEid)
                            {
                                // If was menber two months ago, remember that startdate, not the one for the current membership.
                                // (to handle delayed renewals)
                                if (membership.Active == false &&
                                    membership.DateTerminated > startdate.AddMonths(-2) &&
                                    membership.MemberSince <= startdate.AddMonths(-2))
                                {
                                    if (memberSince == DateTime.MinValue)
                                    {
                                        memberSince = membership.MemberSince;
                                    }

                                    if (membership.Active == false &&
                                        membership.DateTerminated >= startdate &&
                                        membership.MemberSince <= startdate)
                                    {
                                        membershipFound = true; //must be member at startdate
                                    }
                                }
                                else if (membership.Active == false &&
                                         membership.DateTerminated >= startdate &&
                                         membership.MemberSince <= startdate)
                                {
                                    membershipFound = true; //must be member at startdate
                                    if (memberSince == DateTime.MinValue)
                                    {
                                        memberSince = membership.MemberSince;
                                    }
                                }
                                else if (membership.Active == true)
                                {
                                    if (memberSince == DateTime.MinValue)
                                    {
                                        memberSince = membership.MemberSince;
                                    }

                                    membershipFound = true; //must be member now
                                }
                            }
                        }

                        if (!membershipFound)
                        {
                            geoResult["Ej medlem"]++;
                        }
                        else if (memberSince.Date.AddMonths(2) > startdate)
                        {
                            geoResult["Under 2 m&aring;n"]++;
                        }
                        else if (person.Geography != null && (person.Geography.Inherits(selectedGeo) || person.Geography.Identity == selectedGeo))
                        {
                            geoResult["Korrekt"]++;
                        }
                        else
                        {
                            geoResult["Annan"]++;
                        }
                        geoResult["Totalt"]++;
                    }
                    foreach (string kat in geoResult.Keys)
                    {
                        resultSB.Append("&nbsp;&nbsp; " + kat + ":&nbsp;" + geoResult[kat]);
                    }
                    resultSB.Append("<br/>");
                }
            }
        }
        this.LiteralResults.Text = resultSB.ToString();
    }