/// <summary> /// Creates a CommitteeElection object based off of a committee /// </summary> /// <param name="session">A valid session</param> /// <param name="committee">The committee the election pertains to</param> /// <returns>A committeeElection object to be saved to the database, or null if there were no vacancies</returns> public static CommitteeElection CreateElection(ISession session, Committee committee) { CommitteeElection ret = new CommitteeElection(); ret.PertinentCommittee = committee.ID; ret.Started = DateTime.Now; ret.PhaseStarted = ret.Started; ret.Phase = ElectionPhase.WTSPhase; ret.VacanciesToFill = committee.NumberOfVacancies(session); ret.PhaseEndDelta = 0; // return null if there are no vacancies to fill or if there is // already an election for this committee if (ret.VacanciesToFill <= 0 || session.CreateCriteria(typeof(CommitteeElection)) .Add(Restrictions.Eq("PertinentCommittee", committee.ID)) .Add(Restrictions.Not(Restrictions.Eq("Phase", ElectionPhase.ClosedPhase))) .UniqueResult<CommitteeElection>() != null) return null; else return ret; }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["id"] == null || Request.QueryString["id"] == "") throw new HttpException(400, "Invalid election ID"); ElectionID = int.Parse(Request.QueryString["id"]); session = NHibernateHelper.CreateSessionFactory().OpenSession(); // grab the objects based off the committee ID election = CommitteeElection.FindElection(session, ElectionID); if (election == null) Response.Redirect("home.aspx#election_not_found"); committee = Committee.FindCommittee(session, election.PertinentCommittee); if (committee == null) Response.Redirect("home.aspx#committee_not_found"); VacancyCount.Text = election.VacanciesToFill.ToString(); CommitteeNameLiteral.Text = committee.Name; CommitteeNameLiteral2.Text = committee.Name; CommitteeDescription.Text = committee.Description; must_be_tenured.Visible = committee.TenureRequired; user = DatabaseEntities.User.FindUser(session, User.Identity.Name); MakeElectionSpecial.Visible = user.IsAdmin; // expose the pertinent panel based on the state of the election. switch (election.Phase) { case ElectionPhase.WTSPhase: //******************************* //****** Faculty WTS Load ******* //******************************* //Check if WTS already exists List<DatabaseEntities.CommitteeWTS> wtsList = DatabaseEntities.CommitteeWTS.FindCommitteeWTS(session, election.ID); bool wtsAlreadySubmitted = false; foreach (DatabaseEntities.CommitteeWTS wts in wtsList) { if (wts.Election == election.ID && wts.User == user.ID && (!committee.TenureRequired || user.IsTenured) && (!committee.BargainingUnitRequired || user.IsBargainingUnit)) wtsAlreadySubmitted = true; } if(user.CurrentCommittee == committee.ID) { wtsPanelServing.Visible = true; wtsPanelNew.Visible = false; } else if (wtsAlreadySubmitted && (!committee.TenureRequired || user.IsTenured) && (!committee.BargainingUnitRequired || user.IsBargainingUnit)) { wtsPanelExisting.Visible = true; wtsPanelNew.Visible = false; } if ((!committee.TenureRequired || user.IsTenured) && (!committee.BargainingUnitRequired || user.IsBargainingUnit)) FacultyWTS.Visible = true; //Prevent a user from submitting a WTS if a member from their department is on the committee if(DatabaseEntities.Committee.DepartmentRepresented(session, committee, user.Department)) FacultyWTS.Visible = false; break; case ElectionPhase.NominationPhase: if(!user.CanVote) break; if (CommitteeWTSNomination.FindCommitteeWTSNomination(session, election.ID, user.ID).Count == 0) { FacultyNomination.Visible = true; BuildUserNominationOptions(); } else FacultyNominationComplete.Visible = true; break; case ElectionPhase.VotePhase: if(!user.CanVote) break; if (BallotFlag.FindBallotFlag(session, election.ID, user.ID) == null) { FacultyVote.Visible = true; BuildUserVoteOptions(); } else FacultyVoteComplete.Visible = true; break; case ElectionPhase.ClosedPhase: if (!user.IsNEC && !user.IsAdmin) FacultyClosed.Visible = true; break; } JulioButtonHider.Visible = user.IsAdmin; CancelElection.Visible = user.IsAdmin; if (user.IsNEC && election.Phase == ElectionPhase.CertificationPhase) { ActivateTab("CertificationPhase"); NECCertificationPanel.Visible = true; BuildNECVoteTable(); if(Certification.FindCertification(session, election.ID, user.ID) != null) { NECCertifyAgreement.Visible = false; CertifyCheckBox.Visible = false; CertifyButton.Visible = false; CertifyWarning.Visible = false; NECCertificationComplete.Visible = true; } } DaysLeftInPhase(); JulioButton.Text = "Switch to Next Phase"; switch(election.Phase) { case ElectionPhase.WTSPhase: PhaseLiteral.Text = "WTS Phase"; break; case ElectionPhase.NominationPhase: PhaseLiteral.Text = "Nomination Phase"; break; case ElectionPhase.VotePhase: PhaseLiteral.Text = "Voting Phase"; break; case ElectionPhase.CertificationPhase: PhaseLiteral.Text = "Certification Phase"; if(ElectionConflict.FindElectionConflicts(session, election.ID).Count == 0) JulioButton.Text = "Close Election"; break; case ElectionPhase.ConflictPhase: PhaseLiteral.Text = "Conflict Resolution Phase"; JulioButton.Text = "Close Election"; break; case ElectionPhase.ClosedPhase: PhaseLiteral.Text = "Closed"; CancelElection.Visible = false; JulioButtonHider.Visible = false; break; } if(user.IsAdmin) { ActivateTab(election.Phase.ToString()); JulioButton.Visible = true; JulioButtonSpacerText.Visible = true; if(election.Phase >= ElectionPhase.ClosedPhase) closed_tab.Visible = true; if (election.Phase == ElectionPhase.ConflictPhase) { List<ElectionConflict> conflicts = ElectionConflict.FindElectionConflicts(session, election.ID); foreach (ElectionConflict conflict in conflicts) { DatabaseEntities.User conflictUser1 = DatabaseEntities.User.FindUser(session, conflict.FirstUser); if (conflict.Type == ConflictType.ElectedToMultipleCommittees) BuildMultipleCommitteesConflictPanel(conflictUser1, conflict.ID); if (conflict.Type == ConflictType.TooManyDeptMembers) { DatabaseEntities.User conflictUser2 = DatabaseEntities.User.FindUser(session, conflict.SecUser); BuildTooManyDeptConflictPanel(conflictUser1, conflictUser2, conflictUser2.Department, conflict.ID); } } JulioButton.Visible = conflicts.Count == 0; JulioButtonSpacerText.Visible = conflicts.Count == 0; if (conflicts.Count == 0) AdminNoConflicts.Visible = true; else DaysRemaining.Text = "The election cannot be closed while conflicts are present."; conflicts_tab.Visible = true; } if (election.Phase >= ElectionPhase.CertificationPhase) { int numberCertifications = Certification.FindCertifications(session, election.ID).Count; string req_certs = System.Configuration.ConfigurationManager.AppSettings["required_nec_certs"]; int nec_certs = req_certs != null ? int.Parse(req_certs) : 3; AdminCertCount.Text = "There are currently " + numberCertifications.ToString(); if (numberCertifications >= nec_certs) // TODO: Add a button to advance to the next phase. AdminCertCount.Text += " certifications, which is enough to proceed to the next stage."; else AdminCertCount.Text += " certification(s). More NEC members must certify the results before proceeding."; certifications_tab.Visible = true; necprogressbar.Attributes.Add("style", "width: " + Math.Min(100, numberCertifications * (100 / nec_certs)).ToString() + "%"); if(numberCertifications < nec_certs) { HtmlGenericControl pretext = new HtmlGenericControl("span"); pretext.InnerText = certifications_tab_link.Text; certifications_tab_link.Controls.Add(pretext); HtmlGenericControl badge = new HtmlGenericControl("span"); badge.Attributes["class"] = "badge badge-info"; badge.Attributes["style"] = "margin-left: 0.5em;"; badge.InnerText = numberCertifications.ToString(); certifications_tab_link.Controls.Add(badge); } } if (election.Phase >= ElectionPhase.VotePhase) { votes_tab.Visible = true; BuildAdminVoteTable(); } if (election.Phase >= ElectionPhase.NominationPhase) { nominations_tab.Visible = true; BuildAdminNominationTable(); } if(election.Phase >= ElectionPhase.WTSPhase && election.Phase < ElectionPhase.ClosedPhase) wts_tab.Visible = true; //******************************* //******** Admin WTS Load ******* //******************************* List<DatabaseEntities.CommitteeWTS> wtsList = DatabaseEntities.CommitteeWTS.FindCommitteeWTS(session, election.ID); foreach (DatabaseEntities.CommitteeWTS wts in wtsList) { DatabaseEntities.User wtsUser = DatabaseEntities.User.FindUser(session, wts.User); if(wtsUser == null) continue; TableRow tr = new TableRow(); Label revokeNameLabel = new Label(); revokeNameLabel.Text = wtsUser.FirstName + " " + wtsUser.LastName; TableCell td1 = new TableCell(); td1.Controls.Add(revokeNameLabel); Label revokeDeptLabel = new Label(); revokeDeptLabel.Text = wtsUser.Department.ToString(); TableCell td2 = new TableCell(); td2.Controls.Add(revokeDeptLabel); Button revokeButton = new Button(); revokeButton.Text = "Revoke"; revokeButton.CssClass = "btn btn-danger btn-small"; revokeButton.CommandArgument = wts.User.ToString(); revokeButton.Click += new System.EventHandler(this.wtsRevoke_Click); TableCell td3 = new TableCell(); td3.Controls.Add(revokeButton); tr.Cells.Add(td1); tr.Cells.Add(td2); tr.Cells.Add(td3); wtsAdminTable.Rows.Add(tr); } if(wtsList.Count == 0) { TableRow tr = new TableRow(); TableCell td1 = new TableCell(); td1.Controls.Add(new LiteralControl("No WTS forms have been submitted yet.")); td1.ColumnSpan = 3; tr.Controls.Add(td1); wtsAdminTable.Rows.Add(tr); } } }