protected void ButtonSave_Click(object sender, EventArgs e) { Organization org = Organization.PPSE; Election election = Election.September2010; Ballot ballot = Ballot.FromIdentity((int)ViewState[this.ClientID + "SelectedBallot"]); ballot.ClearCandidates(); ballot.DeliveryAddress = this.TextDeliveryAddress.Text; ballot.Count = Int32.Parse(this.TextBallotCount.Text); string[] candidateNames = this.TextCandidates.Text.Split('\r', '\n'); foreach (string candidateNameSource in candidateNames) { if (candidateNameSource.Trim().Length < 3) { continue; } int personId = 0; int idStartIndex = candidateNameSource.LastIndexOf("(#"); if (idStartIndex > 0) { string identityString = candidateNameSource.Substring(idStartIndex + 2); int idEndIndex = identityString.IndexOf(")"); identityString = identityString.Substring(0, idEndIndex); personId = Int32.Parse(identityString); } if (personId == 0) { personId = 1; } ballot.AddCandidate(Person.FromIdentity(personId)); } PopulateCandidates(); Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Valsedel #" + ballot.Identity + " sparades.');", true); }
protected void ButtonAdd_Click(object sender, EventArgs e) { Organization org = Organization.PPSE; Geography geo = this.DropGeographies.SelectedGeography; Election election = Election.September2010; string ballotName = this.TextName.Text; MeetingElectionCandidates candidates = MeetingElection.FromIdentity(Int32.Parse(this.DropPolls.SelectedValue)).Candidates; Ballot ballot = Ballot.Create(election, org, geo, ballotName, 0, string.Empty); Dictionary <string, int> nameLookup = new Dictionary <string, int>(); foreach (MeetingElectionCandidate candidate in candidates) { nameLookup[candidate.Person.Name.ToLowerInvariant()] = candidate.PersonId; } string[] candidateNames = this.TextCandidates.Text.Split('\r', '\n'); foreach (string candidateNameSource in candidateNames) { int personId = 0; int idStartIndex = candidateNameSource.LastIndexOf("(#"); if (idStartIndex > 0) { string identityString = candidateNameSource.Substring(idStartIndex + 2); int idEndIndex = identityString.IndexOf(")"); identityString = identityString.Substring(0, idEndIndex); personId = Int32.Parse(identityString); } if (personId == 0) { // Derive from name string candidateName = candidateNameSource; int parenIndex = candidateName.IndexOfAny(new char[] { '(', ',' }); if (parenIndex >= 0) { candidateName = candidateName.Substring(0, parenIndex); } candidateName = candidateName.ToLowerInvariant().Trim(); if (candidateName.Length < 1) { continue; } personId = nameLookup[candidateName]; } ballot.AddCandidate(Person.FromIdentity(personId)); } Page.ClientScript.RegisterStartupScript(typeof(Page), "OkMessage", @"alert ('Valsedel #" + ballot.Identity + " registrerades.');", true); }