public static XmlDocument EPBOutboundRecords(List <DemoRecords> vr) { XmlDocument response = new XmlDocument(); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("addr", "http://www.fgdc.gov/schemas/address/addr"); ns.Add("addr_type", "http://www.fgdc.gov/schemas/address/addr_type"); XmlSerializer xmlSerializer = new XmlSerializer(typeof(VoterRecordsResponse)); VoterRecordResults records = new VoterRecordResults(); records.VoterRecord = new VoterRecord[vr.Count]; records.TransactionId = "VRI-EPB-Example_" + DateTime.Now.ToString(); int rec = 0; foreach (DemoRecords d in vr) { VoterRecord voter = new VoterRecord(); voter.Voter = new Voter(); voter.Voter.DateOfBirthSpecified = true; voter.Voter.DateOfBirth = Convert.ToDateTime(d.DATE_OF_BIRTH); Name votername = new Name() { FirstName = d.FIRST_NAME, LastName = d.LAST_NAME, FullName = BuildFullName(d.FIRST_NAME, d.MIDDLE_NAME, d.LAST_NAME, d.SUFFIX) }; string[] midname = new string[] { d.MIDDLE_NAME }; votername.MiddleName = midname; voter.Voter.Name = votername; voter.Voter.ResidenceAddress = BuildAddress(d.HOUSE_NUMBER, d.PRE_DIRECTION, d.STREET_NAME, d.STREETTYPE, d.POST_DIRECTION, d.APT_NUM, d.CITY, d.STATE, d.ZIP, d.COUNTRY); //This example does not specify a party, but this is where it would be added Party p = new Party(); p.Name = "Not-specified"; voter.Voter.Party = p; //Known Voter ID Type VoterId vid = new VoterId(); VoterId dmv = new VoterId(); vid.Type = VoterIdType.statevoterregistrationid; dmv.Type = VoterIdType.driverslicense; vid.StringValue = d.VOTERID; dmv.StringValue = d.DMV_NUMBER; voter.Voter.VoterId = new VoterId[2]; voter.Voter.VoterId[0] = vid; voter.Voter.VoterId[1] = dmv; //adding districts - this exammple includes congressional, state senate and state house voter.District = new ReportingUnit[3]; voter.District[0] = BuildReportingUnit("congressional", d.CONGRESSIONAL_DISTRICT); voter.District[1] = BuildReportingUnit("state-senate", d.ST_LEG_UPPER_HOUSE); voter.District[2] = BuildReportingUnit("state-house", d.ST_LEG_LOWER_HOUSE); //Adding locality, precinct and splits voter.Locality = new ReportingUnit[3]; voter.Locality[0] = BuildReportingUnit("county", d.LOCALITY_NAME); voter.Locality[1] = BuildReportingUnit("precinct", d.PRECINCT_NAME); voter.Locality[2] = BuildReportingUnit("split-precinct", d.PRECINCT_SPLIT_NAME); //other information about voter voter.Voter.Gender = d.GENDER; //Protected voter VoterClassification prot = new VoterClassification(); if (d.PROTECTED != "") { prot.Type = VoterClassificationType.protectedvoter; } else { prot.OtherType = "not protected"; prot.Type = VoterClassificationType.other; } //UOCAVA Voter VoterClassification uocava = new VoterClassification(); if (d.UOCAVA_VOTER != "") { uocava.Type = VoterClassificationType.activeduty; } else { uocava.OtherType = "not uocava"; uocava.Type = VoterClassificationType.other; } //absentee ballot status VoterClassification ab = new VoterClassification(); if (d.VOTEBYMAIL_STATUS != "") { ab.OtherType = "absentee ballots sent"; ab.Type = VoterClassificationType.other; } else { ab.OtherType = "no absentee ballot sent"; ab.Type = VoterClassificationType.other; } //NVRA Status VoterClassification nvra = new VoterClassification(); nvra.OtherType = d.VOTER_STATUS; nvra.Type = VoterClassificationType.other; //NVRA Confirmation mailing sent VoterClassification conf = new VoterClassification(); if (d.NVRA_CONFIRMATION != "") { conf.OtherType = "Confirmation sent"; conf.Type = VoterClassificationType.other; } else { conf.OtherType = "No confirmation"; conf.Type = VoterClassificationType.other; } voter.Voter.VoterClassification = new VoterClassification[5]; voter.Voter.VoterClassification[0] = prot; voter.Voter.VoterClassification[1] = uocava; voter.Voter.VoterClassification[2] = ab; voter.Voter.VoterClassification[3] = nvra; voter.Voter.VoterClassification[4] = conf; //Election specific information using the VoterParticipation Object VoterParticipation participation = new VoterParticipation(); Election el = new Election(); el.Name = d.ELECTION_NAME; el.StartDate = Convert.ToDateTime(d.ELECTION_DATE); participation.Election = el; //for ballot style we will need to create an external identifier ExternalIdentifier bsiden = new ExternalIdentifier(); bsiden.Type = IdentifierType.locallevel; bsiden.Value = d.BALLOT_STYLE_NAME; BallotStyle bs = new BallotStyle(); bs.ExternalIdentifier = new ExternalIdentifier[1]; bs.ExternalIdentifier[0] = bsiden; participation.BallotStyle = bs; voter.VoterParticipation = new VoterParticipation[1]; voter.VoterParticipation[0] = participation; records.VoterRecord[rec] = voter; rec++; } VoterRecordsResponse vrresp = records; vrresp.TransactionId = "epb-vri-example"; TextWriter write = new StreamWriter("C:\\dev\\epb_example.xml"); xmlSerializer.Serialize(write, vrresp, ns); return(response); }
public static XmlDocument responseRecord(VoterRecordsRequest lookuprecord) { XmlDocument response = new XmlDocument(); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("addr", "http://www.fgdc.gov/schemas/address/addr"); ns.Add("addr_type", "http://www.fgdc.gov/schemas/address/addr_type"); XmlSerializer xmlSerializer = new XmlSerializer(typeof(VoterRecordsResponse)); VoterRecordResults records = new VoterRecordResults(); records.TransactionId = lookuprecord.TransactionId; VoterRecord vr = new VoterRecord(); vr.Voter = new Voter(); vr.Voter.DateOfBirthSpecified = true; vr.Voter.DateOfBirth = Convert.ToDateTime(lookuprecord.Subject.DateOfBirth); Name votername = new Name() { FirstName = lookuprecord.Subject.Name.FirstName, LastName = lookuprecord.Subject.Name.LastName, FullName = lookuprecord.Subject.Name.FullName }; vr.Voter.Name = votername; vr.Voter.ResidenceAddress = voterAddress(lookuprecord.Subject); vr.Voter.MailingAddress = mailingAddress(lookuprecord.Subject); Party p = new Party(); p.Name = "Not-specified"; vr.Voter.Party = p; VoterId vid = new VoterId(); vid.Type = VoterIdType.statevoterregistrationid; vid.StringValue = "99998888991"; vr.Voter.VoterId = new VoterId[1]; vr.Voter.VoterId[0] = vid; vr.District = new ReportingUnit[1]; vr.District[0] = ru("congressional", "7"); vr.Locality = new ReportingUnit[2]; vr.Locality[0] = ru("county", "Richmond City"); vr.Locality[1] = ru("precinct", "111 - One Hundred Eleven"); records.VoterRecord = new VoterRecord[1]; records.VoterRecord[0] = vr; VoterRecordsResponse vrresp = records; vrresp.TransactionId = "vri-resp" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", ""); TextWriter write = new StreamWriter("C:\\dev\\nvraresponse.xml"); xmlSerializer.Serialize(write, vrresp, ns); //Simple acknowledgement example RequestAcknowledgement ack = new RequestAcknowledgement(); VoterRecordsResponse vrresp2 = ack; vrresp2.TransactionId = "vri-validation" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", ""); TextWriter write2 = new StreamWriter("C:\\dev\\vriack.xml"); xmlSerializer.Serialize(write2, vrresp2, ns); //Rejection request RequestRejection rejection = new RequestRejection(); Error e = new Error(); e.OtherError = "There was an error in processing this request"; rejection.Error = new Error[1]; rejection.Error[0] = e; VoterRecordsResponse resperr = rejection; resperr.TransactionId = "vri-validation" + DateTime.Now.ToString().Replace("/", "").Replace(":", "").Replace(" ", "").Replace("AM", "").Replace("PM", ""); TextWriter writeerr = new StreamWriter("C:\\dev\\vrierr.xml"); xmlSerializer.Serialize(writeerr, resperr, ns); return(response); }