Ejemplo n.º 1
0
 protected void saveButton_Click(object sender, EventArgs e)
 {
     Voter voter=new Voter();
     voter.VoterId = voterIdTextBox.Text;
     voter.VoterName = voterNameTextBox.Text;
     voter.VoterStatus = "Not Casted";
     string msg=voterManager.SaveVoter(voter);
     alertMessage.InnerHtml = msg;
 }
 public void SaveVoter(Voter voter)
 {
     string connectionString = ConfigurationManager.ConnectionStrings["VoteConnectionString"].ConnectionString;
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "INSERT INTO VoterTable (VoterId,VoterName,VoterStatus) VALUES('" + voter.VoterId + "','"
                                                             + voter.VoterName + "','"+voter.VoterStatus+"')";
     SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     sqlCommand.ExecuteNonQuery();
     sqlConnection.Close();
 }
 public Voter GetVoterByVoterId(string voterId)
 {
     string connectionString = ConfigurationManager.ConnectionStrings["VoteConnectionString"].ConnectionString;
     SqlConnection sqlConnection = new SqlConnection(connectionString);
     string query = "SELECT * FROM VoterTable WHERE VoterId = '"+voterId+"'";
     SqlCommand sqlCommand = new SqlCommand(query, sqlConnection);
     sqlConnection.Open();
     Voter voter=null;
     SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
     while (sqlDataReader.Read())
     {
         voter = new Voter();
         voter.VoterId = sqlDataReader["VoterId"].ToString();
         voter.VoterName = sqlDataReader["VoterName"].ToString();
         voter.VoterStatus = sqlDataReader["VoterStatus"].ToString();
     }
     sqlConnection.Close();
     return voter;
 }
 public string SaveVoter(Voter voter)
 {
     if (voter.VoterName == "" || voter.VoterId == "")
     {
         return "Fiedls cannot be empty";
     }
     else if (voter.VoterId.Count() != 13)
     {
         return "Voter Id must be 13 characters long";
     }
     else
     {
         if (voterGateway.GetVoterByVoterId(voter.VoterId) != null)
         {
             return "Voter already exists";
         }
         else
         {
             voterGateway.SaveVoter(voter);
             return "Successfully Saved";
         }
     }
 }