public bool CreateVoter(Voter voter) { var result = _db.Execute(@"IF NOT EXISTS (SELECT * FROM voters WHERE election_id = @ElectionId AND identity_number = @IdentityNumber) BEGIN INSERT INTO dbo.voters (election_id, identity_number) VALUES (@ElectionId, @IdentityNumber) END", new { ElectionId = voter.ElectionId, IdentityNumber = voter.IdentityNumber }); return result == 1; }
private static void GetListOfIdentityNumbersFromTableRows(DataSet dataSet, VoterRegisterFile voterRegisterFile) { for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++) { var voter = new Voter { IdentityNumber = dataSet.Tables[0].Rows[i].ItemArray[0].ToString() }; voterRegisterFile.Voters.Add(voter); } }