コード例 #1
0
        public ActionResult DelegateLogin(ElectionDelegate electionDelegate)
        {
            string errorMessage = "";

            try
            {
                electionDelegate = _delegateManager.RetrieveDelegateByPin(electionDelegate.Pin);
                if (electionDelegate.DelegateID == 0)
                {
                    errorMessage = "Could Not Recognize Pin.";
                    return(RedirectToAction("DelegateLogin", new { errorMessage = errorMessage }));
                }

                else if (!electionDelegate.HasVotedForGrants)
                {
                    return(RedirectToAction("Vote", new { delegateID = electionDelegate.DelegateID.ToString() }));
                }
                else
                {
                    errorMessage = "You have already voted for grants";
                    return(RedirectToAction("DelegateLogin", new { errorMessage = errorMessage }));
                }
            }
            catch (Exception)
            {
                errorMessage = "Unable to Access Grant Voting.";
                return(RedirectToAction("DelegateLogin", new { errorMessage = errorMessage }));
            }
        }
コード例 #2
0
        /// <summary>
        /// inserts a delegate into the delegate table
        /// </summary>
        /// <param name="theDelegate"></param>
        /// <returns></returns>
        public int InsertDelegate(ElectionDelegate theDelegate)
        {
            int rows = 0;
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_insert_delegate", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@FirstName", theDelegate.FirstName);
            cmd.Parameters.AddWithValue("@LastName", theDelegate.LastName);
            try
            {
                conn.Open();
                rows = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }
コード例 #3
0
        /// <summary>
        /// selects a delegate by their pin
        /// </summary>
        /// <param name="pin"></param>
        /// <returns></returns>
        public ElectionDelegate SelectDelegateByPin(string pin)
        {
            ElectionDelegate theDelegate = new ElectionDelegate();
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_select_delegate_by_pin", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Pin", pin);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    theDelegate.DelegateID           = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                    theDelegate.FirstName            = reader.IsDBNull(1) ? null : reader.GetString(1);
                    theDelegate.LastName             = reader.IsDBNull(2) ? null : reader.GetString(2);
                    theDelegate.HasVotedForGrants    = reader.IsDBNull(3) ? false : reader.GetBoolean(3);
                    theDelegate.HasVotedForElections = reader.IsDBNull(4) ? false : reader.GetBoolean(4);
                    theDelegate.Active = reader.IsDBNull(5) ? false : reader.GetBoolean(5);
                    //theDelegate.Pin = reader.IsDBNull(6) ? null : reader.GetString(6);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(theDelegate);
        }
コード例 #4
0
        /// <summary>
        /// Edits a delegate
        /// </summary>
        /// <param name="oldDelegate"></param>
        /// <param name="newDelegate"></param>
        /// <returns></returns>
        public bool EditDelegate(ElectionDelegate oldDelegate, ElectionDelegate newDelegate)
        {
            try
            {
                return 1 == _delegateAccessor.UpdateDelegate(oldDelegate, newDelegate);
            }
            catch (Exception ex)
            {

                throw new ApplicationException("Delegate not activated", ex);
            }
        }
コード例 #5
0
        /// <summary>
        /// Adds delegates to the data access layer
        /// </summary>
        /// <param name="electionDelegate"></param>
        /// <returns></returns>
        public bool AddDelegate(ElectionDelegate electionDelegate)
        {
            try
            {
                return 1 == _delegateAccessor.InsertDelegate(electionDelegate);
            }
            catch (Exception ex)
            {

                throw new ApplicationException("Delegate not added", ex);
            }
        }
コード例 #6
0
        public ActionResult CreateDelegate(ElectionDelegate electionDelegate)
        {
            try
            {
                _delegateManager.AddDelegate(electionDelegate);
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #7
0
        public ActionResult EditDelegate(int id, ElectionDelegate newDelegate)
        {
            try
            {
                var oldDelegate = _delegateManager.RetrieveDelegateByID(id);
                _delegateManager.EditDelegate(oldDelegate, newDelegate);


                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #8
0
        public ActionResult Vote(FormCollection formCollection)
        {
            string errorMessage = "";

            try
            {
                var elections  = _electionManager.RetrieveElectionsByActive(true);
                var delegateID = formCollection[1].ToString();
                if (formCollection.Count != elections.Count + 2)
                {
                    errorMessage = "Please vote for all elections";
                    return(RedirectToAction("Vote", new { delegateID = delegateID, errorMessage = errorMessage }));
                }
                else
                {
                    var oldDelegate = _delegateManager.RetrieveDelegateByID(Int32.Parse(delegateID));

                    var newDelegate = new ElectionDelegate
                    {
                        DelegateID           = oldDelegate.DelegateID,
                        Active               = oldDelegate.Active,
                        FirstName            = oldDelegate.FirstName,
                        LastName             = oldDelegate.LastName,
                        Pin                  = oldDelegate.Pin,
                        HasVotedForGrants    = oldDelegate.HasVotedForGrants,
                        HasVotedForElections = true // mark that this delegate has voted for elections
                    };

                    // gives a vote to the designated candidate
                    for (int i = 2; i < formCollection.Count; i++)
                    {
                        var candidate = _candidateManager.RetrieveCandidateByCandidateID(Int32.Parse(formCollection[i]));
                        candidate.Votes += 1;
                        _candidateManager.EditCandidateVotes(candidate);
                    }

                    _delegateManager.EditDelegate(oldDelegate, newDelegate);
                    return(RedirectToAction("VotingConfirmation"));
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
コード例 #9
0
        public ActionResult UpdateDelegatePin(ElectionDelegate electionDelegate)
        {
            try
            {
                if (_delegateManager.RetrieveDelegateByPin(electionDelegate.Pin).DelegateID != 0)
                {
                    string errorMessage = "The Pin have chosen is already taken";
                    return(RedirectToAction("UpdateDelegatePin", new { delegateID = electionDelegate.DelegateID, errorMessage = errorMessage }));
                }
                else
                {
                    _delegateManager.EditDelegatePin(electionDelegate.DelegateID, electionDelegate.Pin);

                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception)
            {
                return(View(_delegateManager.RetrieveDelegateByID(electionDelegate.DelegateID)));
            }
        }
コード例 #10
0
        public ActionResult Vote(FormCollection grantVotes)
        {
            int delegateID = Int32.Parse(grantVotes[0]);


            try
            {
                if (grantVotes.Count == 9)
                {
                    for (int i = 1; i < grantVotes.Count; i++)
                    {
                        var grant = _grantManager.RetrieveGrantByGrantID(Int32.Parse(grantVotes[i]));
                        grant.Points += 1;
                        _grantManager.EditGrantPointsByID(grant.GrantID, grant.Points);
                    }
                    var oldDelegate = _delegateManager.RetrieveDelegateByID(delegateID);
                    var newDelegate = new ElectionDelegate
                    {
                        DelegateID           = oldDelegate.DelegateID,
                        FirstName            = oldDelegate.FirstName,
                        LastName             = oldDelegate.LastName,
                        Active               = oldDelegate.Active,
                        HasVotedForElections = oldDelegate.HasVotedForElections,
                        HasVotedForGrants    = true,
                        Pin = oldDelegate.Pin
                    };
                    _delegateManager.EditDelegate(oldDelegate, newDelegate);

                    return(RedirectToAction("GrantVoteConfirmation"));
                }
                else
                {
                    return(RedirectToAction("Vote", new { delegateID = delegateID }));
                }
            }
            catch (Exception)
            {
                return(RedirectToAction("DelegateLogin"));
            }
        }
コード例 #11
0
        /// <summary>
        /// selects a list of delegates by active
        /// </summary>
        /// <param name="active"></param>
        /// <returns></returns>
        public List <ElectionDelegate> SelectDelegatesByActive(bool active)
        {
            List <ElectionDelegate> theDelegates = new List <ElectionDelegate>();
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_select_delegates_by_active", conn);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@Active", active);

            try
            {
                conn.Open();
                var reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        ElectionDelegate theDelegate = new ElectionDelegate();

                        theDelegate.DelegateID           = reader.IsDBNull(0) ? 0 : reader.GetInt32(0);
                        theDelegate.FirstName            = reader.IsDBNull(1) ? null : reader.GetString(1);
                        theDelegate.LastName             = reader.IsDBNull(2) ? null : reader.GetString(2);
                        theDelegate.HasVotedForGrants    = reader.IsDBNull(3) ? false : reader.GetBoolean(3);
                        theDelegate.HasVotedForElections = reader.IsDBNull(4) ? false : reader.GetBoolean(4);
                        theDelegate.Active = reader.IsDBNull(5) ? false : reader.GetBoolean(5);

                        theDelegates.Add(theDelegate);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return(theDelegates);
        }
コード例 #12
0
        /// <summary>
        /// updates a delegate
        /// </summary>
        /// <param name="oldDelegate"></param>
        /// <param name="newDelegate"></param>
        /// <returns></returns>
        public int UpdateDelegate(ElectionDelegate oldDelegate, ElectionDelegate newDelegate)
        {
            int rows = 0;
            var conn = DBConnection.GetConnection();
            var cmd  = new SqlCommand("sp_update_delegate", conn);

            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@DelegateID", oldDelegate.DelegateID);

            cmd.Parameters.AddWithValue("@OldFirstName", oldDelegate.FirstName);
            cmd.Parameters.AddWithValue("@OldLastName", oldDelegate.LastName);
            cmd.Parameters.AddWithValue("@OldHasVotedForGrants", oldDelegate.HasVotedForGrants);
            cmd.Parameters.AddWithValue("@OldHasVotedForElections", oldDelegate.HasVotedForElections);
            cmd.Parameters.AddWithValue("@OldActive", oldDelegate.Active);

            cmd.Parameters.AddWithValue("@NewFirstName", newDelegate.FirstName);
            cmd.Parameters.AddWithValue("@NewLastName", newDelegate.LastName);
            cmd.Parameters.AddWithValue("@NewHasVotedForGrants", newDelegate.HasVotedForGrants);
            cmd.Parameters.AddWithValue("@NewHasVotedForElections", newDelegate.HasVotedForElections);
            cmd.Parameters.AddWithValue("@NewActive", newDelegate.Active);
            try
            {
                conn.Open();
                rows = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }

            return(rows);
        }