/// <summary> /// This function sets the phase of the specified election. You still /// to call transaction.Commit() to ensure pending changes are saved. /// </summary> /// <param name="session">A valid session.</param> /// <param name="id">The id of the election to edit.</param> /// <param name="electionPhase">The new phase of the election.</param> public virtual void SetPhase(ISession session, ElectionPhase electionPhase) { this.Phase = electionPhase; Committee com = Committee.FindCommittee(session, PertinentCommittee); if (electionPhase == ElectionPhase.WTSPhase) { List<User> userList = User.GetAllUsers(session); userList.RemoveAll(x => (!(!com.TenureRequired || x.IsTenured) || !(!com.BargainingUnitRequired || x.IsBargainingUnit))); userList.RemoveAll(x => (x.CurrentCommittee == com.ID)); nEmailHandler emailHandler = new nEmailHandler(); emailHandler.sendGenericCommitteePhase(this, userList, "committeePhaseWTS"); } else if (electionPhase == ElectionPhase.NominationPhase) { List<User> userList = User.GetAllUsers(session); nEmailHandler emailHandler = new nEmailHandler(); userList.RemoveAll(x => (!x.CanVote)); emailHandler.sendGenericCommitteePhase(this, userList, "committeePhaseNomination"); } else if (electionPhase == ElectionPhase.VotePhase) { // if theres no need to enter the nomination phase, // automatically enter nominations for users who //submitted wts if (!ShouldEnterNominationPhase(session)) { List<CommitteeWTS> wtses = CommitteeWTS.FindCommitteeWTS(session, ID); foreach (CommitteeWTS wts in wtses) { ISession nomSession = NHibernateHelper.CreateSessionFactory().OpenSession(); Nomination nomination = new Nomination(); nomination.User = wts.User; nomination.Election = ID; nomSession.SaveOrUpdate(nomination); nomSession.Flush(); } } // distribute emails prompting faculty members to come List<User> userList = User.GetAllUsers(session); userList.RemoveAll(x => (!(x.CanVote || x.IsAdmin))); nEmailHandler emailHandler = new nEmailHandler(); emailHandler.sendGenericCommitteePhase(this, userList, "committeePhaseVote"); // vote } else if (electionPhase == ElectionPhase.CertificationPhase) { ConflictLogic(session); // Get an idea of what the conflicts will be. List<User> userList = User.GetAllUsers(session); userList.RemoveAll(x => (!(x.IsNEC || x.IsAdmin))); nEmailHandler emailHandler = new nEmailHandler(); emailHandler.sendGenericCommitteePhase(this, userList, "committeePhaseCertification"); } else if (electionPhase == ElectionPhase.ConflictPhase) { ConflictLogic(session); // Re-calculate in case the admin fixed it up. // maybe send out emails telling admins / NEC that there are conflicts? List<User> userList = User.GetAllUsers(session); userList.RemoveAll(x => (!(x.IsNEC || x.IsAdmin))); nEmailHandler emailHandler = new nEmailHandler(); emailHandler.sendGenericCommitteePhase(this, userList, "committeePhaseConflict"); } else if (electionPhase == ElectionPhase.ClosedPhase) { // Put the users into the correct committee. Dictionary<string, int> winners = GetResults(session); List<User> winningUsers = new List<User>(); foreach (string email in winners.Keys) { User u = User.FindUser(session, email); u.CurrentCommittee = PertinentCommittee; session.SaveOrUpdate(u); } } // Store the current date in the PhaseStarted field this.PhaseStarted = DateTime.Now; this.PhaseEndDelta = 0; session.SaveOrUpdate(this); session.Flush(); }
/// <summary> /// This function sets the phase of the specified election. You still /// to call transaction.Commit() to ensure pending changes are saved. /// </summary> /// <param name="session">A valid session.</param> /// <param name="ID">The id of the election to edit.</param> /// <param name="electionPhase">The new phase of the election.</param> public static void SetPhase(ref ISession session, int ID, ElectionPhase electionPhase) { // pull a list of all the committee elections from the database. var committees = session.CreateCriteria(typeof(CommitteeElection)).List<CommitteeElection>(); for (int i = 0; i < committees.Count; i++) { // after searching through the list, if we've found the ID // of the comitttee election we want to edit, change the phase // to the one specified by the parameters, then save our changes. // then do some other stuff based on what the new phase is if (committees[i].ID == ID) { committees[i].Phase = electionPhase; session.SaveOrUpdate(committees[i]); if (electionPhase == ElectionPhase.WTSPhase) { // email out WTS emails to redirect people to the site } else if (electionPhase == ElectionPhase.BallotPhase) { // not much needs to be done here } else if (electionPhase == ElectionPhase.VotePhase) { // distribute emails prompting faculty members to come // vote } else if (electionPhase == ElectionPhase.ConflictPhase) { // not much needs to be done here. } else if (electionPhase == ElectionPhase.ResultPhase) { // send out emails informing people of the results. // send out emails teling NEC people to certify results } session.Flush(); return; } } }