예제 #1
0
    protected void ButtonChangeVote_Click(object sender, EventArgs e)
    {
        MeetingElection         poll        = MeetingElection.FromIdentity(Int32.Parse(Request.QueryString["PollId"]));
        InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser);

        if (voterStatus == InternalPollVoterStatus.HasAlreadyVoted)
        {
            string verificationCode = this.TextVerificationCode.Text;

            try
            {
                MeetingElectionVote vote = MeetingElectionVote.FromVerificationCode(verificationCode);

                if (vote.InternalPollId == poll.Identity)
                {
                    Response.Redirect(Request.RawUrl + "&VerificationCode=" + verificationCode);
                }
            }
            catch (Exception)
            {
                ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                    "alert ('There is no such verification code associated with this poll.');",
                                                    true);
            }
        }
    }
예제 #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string pollIdParameter = Request.QueryString["PollId"];

            if (string.IsNullOrEmpty(pollIdParameter))
            {
                PopulatePollGrid();
                this.PanelPollList.Visible  = true;
                this.PanelVoting.Visible    = false;
                this.PanelPollIntro.Visible = false;
            }
            else
            {
                MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(pollIdParameter));
                this.LabelPollName1.Text = poll.Name;

                InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser);

                if (!poll.VotingOpen)
                {
                    this.PanelVoting.Visible       = false;
                    this.PanelVotingClosed.Visible = true;
                }
                else if (voterStatus == InternalPollVoterStatus.NotEligibleForPoll)
                {
                    this.PanelVoting.Visible = false;
                    this.PanelNoVote.Visible = true;
                }
                else if (voterStatus == InternalPollVoterStatus.HasAlreadyVoted)
                {
                    string verificationCode = Request.QueryString["VerificationCode"];

                    if (string.IsNullOrEmpty(verificationCode))
                    {
                        this.PanelVoting.Visible    = false;
                        this.PanelComplete.Visible  = true;
                        this.PanelEnterCode.Visible = true;
                    }
                    else
                    {
                        // The voter wishes to redo his/her vote

                        PopulateLists(poll, verificationCode);
                        this.ListVote.DataBind();
                        this.ListCandidates.DataBind();
                        this.ButtonVote.Enabled = true;
                    }
                }
                else // open; the voter has not yet voted
                {
                    PopulateLists(poll, string.Empty);

                    this.ListCandidates.DataBind();
                }
            }
        }
    }
예제 #3
0
    protected void ButtonVote_Click(object sender, EventArgs e)
    {
        MeetingElection poll = MeetingElection.FromIdentity(Int32.Parse(Request.QueryString["PollId"]));

        if (!poll.VotingOpen)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('This poll has closed. You can not cast the vote.');",
                                                true);
            return;
        }


        if (this.ListVote.Items.Count == 0)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('You need to pick one or more candidates in order to cast a vote.');",
                                                true);
            return;
        }

        if (this.ListVote.Items.Count > poll.MaxVoteLength)
        {
            ScriptManager.RegisterStartupScript(this, Page.GetType(), "nope",
                                                "alert ('You have chosen too many candidates. The maximum number is " + poll.MaxVoteLength.ToString() + ". Please remove at least " + (this.ListVote.Items.Count - poll.MaxVoteLength).ToString() + ".');",
                                                true);
            return;
        }

        string verificationCode             = Request.QueryString["VerificationCode"];
        InternalPollVoterStatus voterStatus = poll.GetVoterStatus(_currentUser);

        if (voterStatus == InternalPollVoterStatus.CanVote || (!string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.HasAlreadyVoted))
        {
            this.PanelPollIntro.Visible = false;
            this.PanelVoting.Visible    = false;
            this.PanelComplete.Visible  = true;
            this.PanelCode.Visible      = true;

            MeetingElectionVote vote = null;

            if (string.IsNullOrEmpty(verificationCode) && voterStatus == InternalPollVoterStatus.CanVote)
            {
                vote = poll.CreateVote(_currentUser, Request.UserHostAddress.ToString());
            }
            else
            {
                vote = MeetingElectionVote.FromVerificationCode(verificationCode);
                vote.Clear();
            }


            this.LabelReference.Text = vote.VerificationCode;

            for (int index = 0; index < this.ListVote.Items.Count; index++)
            {
                MeetingElectionCandidate candidate =
                    MeetingElectionCandidate.FromIdentity(Int32.Parse(this.ListVote.Items[index].Value));

                vote.AddDetail(index + 1, candidate);
            }
        }
    }