Exemple #1
0
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            VoterBusinessLogic vbl = new VoterBusinessLogic();
            int    voterId         = Convert.ToInt32(txtVoterId.Text);
            string password        = txtPassword.Text;
            bool   isLogInSuccess  = vbl.Login(voterId, password);

            if (isLogInSuccess)
            {
                //lblMessage.Text = "Successfully Logged in.";
                //lblMessage.ForeColor = System.Drawing.Color.Green;
                Session["VoterId"] = voterId;
                //if (Session["role"]!=null)
                //{
                //    Response.Redirect("Admin");

                //}
                Response.Redirect("UserPage");
            }
            else
            {
                lblMessage.Text      = "Log In failed.";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
 public override void OnAuthorization(HttpActionContext actionContext)
 {
     if (actionContext.Request.Headers.Authorization == null)
     {
         actionContext.Response = actionContext.Request
                                  .CreateResponse(HttpStatusCode.Unauthorized);
     }
     else
     {
         string authenticationToken = actionContext.Request.Headers
                                      .Authorization.Parameter;
         string decodedAuthenticationToken = Encoding.UTF8.GetString(
             Convert.FromBase64String(authenticationToken));
         string[]           usernamePasswordArray = decodedAuthenticationToken.Split(':');
         string             username = usernamePasswordArray[0];
         int                voterId  = Convert.ToInt32(username);
         string             password = usernamePasswordArray[1];
         VoterBusinessLogic vbl      = new VoterBusinessLogic();
         if (vbl.Login(voterId, password))
         {
             Thread.CurrentPrincipal = new GenericPrincipal(
                 new GenericIdentity(username), null);
         }
         else
         {
             actionContext.Response = actionContext.Request
                                      .CreateResponse(HttpStatusCode.Unauthorized);
         }
     }
 }
Exemple #3
0
        // GET api/values
        public List <VoterProperties> Get()
        {
            VoterBusinessLogic vbl = new VoterBusinessLogic();
            DataSet            ds  = new DataSet();

            ds = vbl.GetVoterList();

            List <VoterProperties> voterList = new List <VoterProperties>();

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                VoterProperties vp = new VoterProperties();
                //foreach (DataColumn col in ds.Tables[0].Columns)
                //{
                vp.VoterId     = Convert.ToInt32(dr["Id"]);
                vp.FullName    = dr["FullName"].ToString();
                vp.Email       = dr["Email"].ToString();
                vp.PhoneNumber = dr["PhoneNumber"].ToString();
                vp.Gender      = dr["Gender"].ToString();
                vp.DateOfBirth = Convert.ToDateTime(dr["DateOfBirth"]);
                //row.Add(col.ColumnName, dr[col]);
                //}
                voterList.Add(vp);
            }
            return(voterList);
            // return new string[] { "value1", "value2" };
        }
Exemple #4
0
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                VoterBusinessLogic vbl   = new VoterBusinessLogic();
                VoterProperties    voter = new VoterProperties();
                voter.FullName    = txtFullName.Text;
                voter.Email       = txtEmail.Text;
                voter.PhoneNumber = txtPhoneNumber.Text;
                voter.VoterId     = Convert.ToInt32(txtVoterId.Text);
                voter.Gender      = RadioButtonListGender.SelectedValue;
                voter.DateOfBirth = Convert.ToDateTime(txtDOB.Text);

                voter.Password = txtPassword.Text;

                vbl.Register(voter);

                lblMessage.Text      = "Voter with Id, " + voter.VoterId + " has been added successfully.";
                lblMessage.ForeColor = System.Drawing.Color.Green;
            }
        }
        protected void btnSignUp_Click(object sender, EventArgs e)
        {
            VoterBusinessLogic vbl   = new VoterBusinessLogic();
            VoterProperties    voter = new VoterProperties();

            voter.FullName    = txtFullName.Text;
            voter.Email       = txtEmail.Text;
            voter.PhoneNumber = txtPhoneNumber.Text;
            voter.VoterId     = Convert.ToInt32(txtVoterId.Text);
            voter.Gender      = RadioButtonListGender.SelectedValue;
            voter.DateOfBirth = Convert.ToDateTime(txtDOB.Text);

            voter.Password = txtPassword.Text;
            bool isEditSuccess = vbl.EditVoter(voter);

            if (!string.IsNullOrEmpty(Session["role"] as string))
            {
                Response.Redirect("Admin");
            }
            else
            {
                Response.Redirect("UserPage");
            }
        }
        static void Main()
        {
            /*  try
             * {
             *    try
             *    {
             *        Console.WriteLine("Enter First Number");
             *        int FN = Convert.ToInt32(Console.ReadLine());
             *
             *
             *        Console.WriteLine("Enter Second Number");
             *        int SN = Convert.ToInt32(Console.ReadLine());
             *
             *
             *        int Result = FN / SN;
             *        Console.WriteLine("Result = {0}", Result);
             *    }
             *    catch (Exception ex)
             *    {
             *        string filePath = @"C:\Sample Files\Log1.txt";
             *        if (File.Exists(filePath))
             *        {
             *            StreamWriter sw = new StreamWriter(filePath);
             *            sw.Write(ex.GetType().Name + ex.Message + ex.StackTrace);
             *            sw.Close();
             *            Console.WriteLine("There is a problem! Plese try later");
             *        }
             *        else
             *        {
             *            //To retain the original exception pass it as a parameter
             *            //to the constructor, of the current exception
             *            throw new FileNotFoundException(filePath + " Does not Exist", ex);
             *        }
             *    }
             * }
             * catch (Exception ex)
             * {
             *    //ex.Message will give the current exception message
             *    Console.WriteLine("Current or Outer Exception = " + ex.Message);
             *
             *
             *    //Check if inner exception is not null before accessing Message property
             *    //else, you may get Null Reference Excception
             *    if (ex.InnerException != null)
             *    {
             *        Console.WriteLine("Inner Exception = "+ ex.InnerException.Message);
             *    }
             * }*/



            //{
            //    Console.WriteLine("Welcome to Online Voting Project.\nPress enter to get employee details.");
            //    Console.ReadKey();
            //    Program program = new Program();
            //    Voter voter1 = new Voter();
            //    voter1.Register(1, "Ram1 Bilas", "*****@*****.**", 409423, "Male", new DateTime(1991, 1, 18), "rambilas1");
            //    Console.WriteLine(voter1.GetVoterDetails());

            //    Console.WriteLine("*********voter2****************");

            //    Voter voter2 = new Voter();
            //    voter2.Register(2, "Ram2 Bilas", "*****@*****.**", 3209423, "Male", new DateTime(1992, 1, 18), "rambilas2");
            //    Console.WriteLine(voter2.GetVoterDetails());

            //    Console.WriteLine("***********Editing name of voter2**************");
            //    voter2.EditVoter(2, voter2, "Ram3 Bilas");
            //    Console.WriteLine(voter2.GetVoterDetails());
            //}


            string   yesOrNo = "";
            int      voterId;
            string   password;
            DateTime dob;

            Console.WriteLine("Welcome to Online Voting Project.\nPress enter to get employee details.");
            do
            {
                VoterProperties    vp  = new VoterProperties();
                VoterBusinessLogic vbl = new VoterBusinessLogic();
                Console.WriteLine("\n Please Enter \"1 to Register\"\t \"2 to Login\"\t \"3 to Edit\" and \"4 to Delete,  Voter.");
                int i = Convert.ToInt32(Console.ReadLine());


                switch (i)
                {
                case 1:

                    Console.WriteLine("enter Voter Id");
                    vp.VoterId = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("enter Name");
                    vp.FullName = Console.ReadLine();
                    Console.WriteLine("enter Email");
                    vp.Email = Console.ReadLine();
                    Console.WriteLine("enter phone number");
                    //  vp.PhoneNumber = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter gender");
                    vp.Gender = Console.ReadLine();
                    Console.WriteLine("enter Date of Birth");
                    Boolean x = DateTime.TryParse(Console.ReadLine(), out dob);
                    vp.DateOfBirth = dob;
                    Console.WriteLine("enter Password");
                    vp.Password = Console.ReadLine();
                    vbl.Register(vp);


                    //   Hashtable hashtable = vbl.GetVoterList();
                    //  DisplayVoters(hashtable);
                    break;

                case 2:
                    Console.WriteLine("enter Voter Id to Login");
                    voterId = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("enter Password");
                    password = Console.ReadLine();
                    bool str = vbl.Login(voterId, password);
                    if (str)
                    {
                        Console.WriteLine("\nLogin Successful.");
                    }
                    else
                    {
                        Console.WriteLine("\nLogin failed.");
                    }


                    //   hashtable = vbl.GetVoterList();
                    ////  DisplayVoters(hashtable);
                    break;

                case 3:
                    Console.WriteLine("Enter Voter Id to edit the voter's detail.");
                    voterId = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("enter Password");
                    password = Console.ReadLine();
                    bool bol = vbl.Login(voterId, password);
                    if (bol)
                    {
                        VoterProperties vpp = new VoterProperties();
                        Console.WriteLine("\n enter details to edit.");
                        vpp.VoterId  = voterId;
                        vpp.Password = password;
                        Console.WriteLine("enter full name if you wanna change");
                        vpp.FullName = Console.ReadLine();
                        Console.WriteLine("enter email if want to change");
                        vpp.Email = Console.ReadLine();
                        Console.WriteLine("enter phone number if want to change");
                        //vpp.PhoneNumber = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("enter gender if want to change");
                        vpp.Email = Console.ReadLine();
                        Console.WriteLine("enter Date of Birth if want to change");
                        x = DateTime.TryParse(Console.ReadLine(), out dob);
                        vpp.DateOfBirth = dob;

                        Console.WriteLine(vbl.EditVoter(vpp) ? "Edit Successful" : "Edit failed");
                    }
                    else
                    {
                        Console.WriteLine("\nValidation failed for editing data.");
                    }
                    //  hashtable = vbl.GetVoterList();
                    //DisplayVoters(hashtable);

                    break;

                case 4:
                    Console.WriteLine("Enter Voter Id to Delete the voter.");
                    voterId = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("enter Password");
                    password = Console.ReadLine();
                    bol      = false;
                    bol      = vbl.Login(voterId, password);
                    if (bol)
                    {
                        bol = false;
                        bol = vbl.DeleteVoter(voterId);
                        if (bol)
                        {
                            Console.WriteLine("Voter with id {0} successfully deleted.", voterId);
                        }
                        else
                        {
                            Console.WriteLine("Voter with id {0} deletion failed.", voterId);
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nValidation failed for deleting data.");
                    }
                    //  hashtable = vbl.GetVoterList();
                    // DisplayVoters(hashtable);

                    break;

                case 5:

                    break;

                default:
                    break;
                }

                Console.WriteLine("Do you want to continue? yes or no");
                yesOrNo = Console.ReadLine();
            } while (yesOrNo.ToLower() != "no");
        }