/// <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; }
/// <summary> /// Adds the specified user to the specified committee /// </summary> /// <param name="session">A valid session.</param> /// <param name="user">A reference to the user to be added</param> /// <param name="committee">The name of the committee the user is to be added to.</param> /// <returns>True if the operation was successful.</returns> public virtual bool AddToCommittee(ISession session, Committee com) { if (com != null) { // Note that the logical if then (A -> B) binary operation // is equivalent to (~A v B) if ((!com.TenureRequired || this.IsTenured) && // logical if then (!com.BargainingUnitRequired || this.IsBargainingUnit) && // logical if then com.NumberOfVacancies(session) > 0) { this.CurrentCommittee = com.ID; session.SaveOrUpdate(this); session.Flush(); return true; } else return false; } else return false; }