Ejemplo n.º 1
0
 public bool Equals(VoterCard other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(Equals(other.ElectionEvent, this.ElectionEvent) && Equals(other.Citizen, this.Citizen) && other.Id == this.Id && other.Valid.Equals(this.Valid));
 }
Ejemplo n.º 2
0
 public bool Equals(VoterCard other)
 {
     if (ReferenceEquals(null, other))
     {
         return false;
     }
     if (ReferenceEquals(this, other))
     {
         return true;
     }
     return Equals(other.ElectionEvent, this.ElectionEvent) && Equals(other.Citizen, this.Citizen) && other.Id == this.Id && other.Valid.Equals(this.Valid);
 }
Ejemplo n.º 3
0
 private VoterCard PriLoadVoterCard(int id)
 {
     Contract.Requires(this.Transacting(), "This method must be performed in a transaction.");
     Contract.Requires(PriExistsWithId("voter_card", id), "Votercard must exist in the database to be loaded.");
     Contract.Ensures(Contract.Result<VoterCard>() != null);
     MySqlCommand command = Prepare("SELECT * FROM voter_card v LEFT JOIN person p ON p.id=v.person_id WHERE v.id=@id");
     command.Parameters.AddWithValue("@id", id);
     VoterCard v = new VoterCard();
     int citizenId = 0;
     Query(command, (MySqlDataReader rdr) =>
     {
         rdr.Read();
         citizenId = rdr.GetInt32("person_id");
         v.ElectionEvent = Settings.Election;
         v.Id = rdr.GetInt32("id");
         v.IdKey = rdr.GetString("id_key");
         v.Valid = (rdr.GetUInt32("valid") == 1);
     });
     v.Citizen = PriLoadCitizen(citizenId);
     return v;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Update all persons in the dataset with this update
        /// </summary>
        /// <param name="updateFunc"></param>
        public void UpdateVoterCards()
        {
            var connection = new MySqlConnection(this._connectionString);
            connection.Open();
            const string Query = "SELECT id FROM person p WHERE eligible_to_vote=1 AND p.id NOT IN (SELECT person_id FROM voter_card v WHERE v.person_id = p.id AND v.valid=1);";
            var loadEligiblePeople = new MySqlCommand(Query, connection);
            MySqlDataReader rdr = null;

            try
            {
                rdr = loadEligiblePeople.ExecuteReader();

                while (rdr.Read())
                {
                    var v = new VoterCard();
                    var id = rdr.GetInt32("id");
                    v.Citizen = LoadCitizen(id);
                    v.ElectionEvent = Settings.Election;
                    v.IdKey = VoterCard.GenerateIdKey();
                    v.Valid = true;
                    DoTransaction(() => PriSaveNew(v));
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (rdr != null) rdr.Close();
                connection.Close();
            }

            //Update people that are not in the raw data
            DoTransaction(
                () => this.MarkVoterCardsInvalidForCitizensUneligibleToVote()
            );
        }
Ejemplo n.º 5
0
 private int PriSaveNew(VoterCard voterCard)
 {
     Contract.Requires(this.Transacting(), "Must be called within a transaction");
     Contract.Requires(voterCard != null);
     Contract.Requires(voterCard.Id == 0);
     Contract.Requires(voterCard.Citizen != null);
     Contract.Requires(PriExistsWithId("person", voterCard.Citizen.DbId), "A voter card must belong to a person in the database");
     Contract.Requires(voterCard.IdKey != null);
     /*Contract.Requires(FindVoterCards(new Dictionary<VoterCardSearchParam, object>()
                                                                 {
                                                                     {VoterCardSearchParam.IdKey,voterCard.IdKey}
                                                                 }).Count == 0, "Voter card id-key must be unique!");*/
     Contract.Requires(!(voterCard.Id > 0) || PriExistsWithId("voter_card", voterCard.Id));
     MySqlCommand saveVoterCard = Prepare("INSERT INTO " +
                                          "  voter_card (" +
                                          "      person_id, " +
                                          "      valid, " +
                                          "      id_key" +
                                          "  )" +
                                          "VALUES" +
                                          "  (" +
                                          "      @personId," +
                                          "      @valid," +
                                          "      @idKey" +
                                          "  )" +
                                          ";" +
                                          "" +
                                          "SELECT LAST_INSERT_ID();");
     var voterCardMapping = new Dictionary<string, string>()
                                                      {
                                                          {"personId",voterCard.Citizen.DbId.ToString()},
                                                          {"valid",voterCard.Valid ? "1" : "0"},
                                                          {"idKey",voterCard.IdKey}
                                                      };
     foreach (var kv in voterCardMapping)
     {
         saveVoterCard.Parameters.AddWithValue("@" + kv.Key, kv.Value);
     }
     return Convert.ToInt32(ScalarQuery(saveVoterCard));
 }
Ejemplo n.º 6
0
 private void PriSave(VoterCard voterCard)
 {
     Contract.Requires(this.Transacting(), "Must be called within a transaction");
     Contract.Requires(voterCard != null);
     Contract.Requires(voterCard.Id > 0);
     Contract.Requires(voterCard.Citizen != null);
     Contract.Requires(PriExistsWithId("person", voterCard.Citizen.DbId), "A voter card must belong to a person in the database");
     Contract.Requires(voterCard.IdKey != null);
     Contract.Requires(PriExistsWithId("voter_card", voterCard.Id));
     MySqlCommand updateVoterCard = Prepare("UPDATE" +
                                            "    voter_card  " +
                                            "SET" +
                                            "    person_id=@personId," +
                                            "    valid=@valid," +
                                            "    id_key=@idKey;");
     var voterCardMapping = new Dictionary<string, string>()
                                             {
                                                 {"personId",voterCard.Citizen.DbId.ToString()},
                                                 {"valid",voterCard.Valid ? "1" : "0"},
                                                 {"idKey",voterCard.IdKey}
                                             };
     foreach (var kv in voterCardMapping)
     {
         updateVoterCard.Parameters.AddWithValue("@" + kv.Key, kv.Value);
     }
     Execute(updateVoterCard);
 }