コード例 #1
0
ファイル: DaysFacet.cs プロジェクト: BellevueCollege/CtcApi
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <note>This method assumes that the <b>Title</b> field in the database contains unique values AND the existence of certain values.</note>
        /// <param name="dbContext"></param>
        /// <exception cref="ArgumentNullException"><paramref name="dbContext"/> is null.</exception>
        /// <exception cref="InvalidOperationException">A valid option value was not specified when the class was instantiated.</exception>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    if (_option == Options.All)
                    {
                        // don't filter by days
                        return(s => true);
                    }

                    string days = GetDaysTitle();

                    if (days == "MTWThF")
                    {
                        return(s => db.InstructionDetails.Join(db.Days, i => i.DayID, d => d.DayID, (i, d) => new { i, d })
                               .Any(h => h.i.ClassID == s.ClassID && (h.d.Title == days || h.d.Title.ToUpper() == "DAILY")));
                    }
                    // else
                    return(s => db.InstructionDetails.Join(db.Days, i => i.DayID, d => d.DayID, (i, d) => new { i, d })
                           .Any(h => h.d.Title == days && h.i.ClassID == s.ClassID));
                }

                throw new ArgumentNullException("dbContext", "Database context is not valid.");
            }

            throw new ArgumentNullException("dbContext", "Database context is null.");
        }
コード例 #2
0
ファイル: TimeFacet.cs プロジェクト: BellevueCollege/CtcApi
        /// <summary>
        /// Filters the <see cref="SectionEntity"/> query to only include records between the specified start and end times
        /// </summary>
        /// <param name="dbContext"></param>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            OdsContext db = dbContext as OdsContext;

            DateTime startTime = Utility.GetHpTime(_startTimeRange);
            DateTime endTime   = Utility.GetHpTime(_endTimeRange);

            return
                (s => ((!s.StartTime.HasValue) || (s.StartTime.Value.CompareTo(startTime) >= 0 && s.StartTime.Value.CompareTo(endTime) <= 0)));
        }
コード例 #3
0
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <param name="dbContext"></param>
        /// <exception cref="ArgumentNullException"><paramref name="dbContext"/> is null.</exception>
        /// <exception cref="InvalidOperationException">A valid option value was not specified when the class was instantiated.</exception>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    return(s => _yearQuarterIDs.Contains(s.YearQuarterID));
                }

                throw new ArgumentNullException("dbContext", "Database context is not valid.");
            }

            throw new ArgumentNullException("dbContext", "Database context is null.");
        }
コード例 #4
0
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <param name="dbContext"></param>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    return(s => (s.Credits < 1 ? 1 : Math.Floor(s.Credits)) == _credits || (s.VariableCredits == true && Math.Floor(s.Credits) >= _credits));
                }

                throw new ArgumentNullException("dbContext", "Database context is not valid.");
            }

            throw new ArgumentNullException("dbContext", "Database context is null.");
        }
コード例 #5
0
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <param name="dbContext"></param>
        /// <exception cref="ArgumentNullException"><paramref name="dbContext"/>Is null, or is not a valid <see cref="OdsContext"/> object.</exception>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    Expression <Func <T, bool> > filter;

                    // TODO: refactor how we count quarters (forward and back)
                    // idea:
                    //	0		- 1 quarter, current
                    // < 0	- that many *additional* previous quarters
                    // > 0	- that many *additional* future quarters
                    if (_quarterCount < 0)
                    {
                        // include current and PREVIOUS quarters
                        int quarterCount = Math.Abs(_quarterCount);
                        filter = s => db.YearQuarters.Join(db.WebRegistrationSettings, y => y.YearQuarterID, r => r.YearQuarterID, (y, r) => new { y, r })
                                 .DefaultIfEmpty()
                                 .Where(c => (c.r.FirstRegistrationDate != null && c.r.FirstRegistrationDate <= _registrationDate || c.y.FirstClassDay <= _today) &&
                                        c.y.YearQuarterID != _yrqMax)
                                 .OrderByDescending(c => c.y.YearQuarterID)
                                 .Take(quarterCount)
                                 .Any(c => c.y.YearQuarterID == s.YearQuarterID);
                    }
                    else
                    {
                        // include current and FUTURE quarters
                        filter = s => db.YearQuarters.Join(db.WebRegistrationSettings, y => y.YearQuarterID, r => r.YearQuarterID, (y, r) => new { y, r })
                                 .DefaultIfEmpty()
                                 .Where(c => (c.r.LastRegistrationDate != null && c.r.LastRegistrationDate > _registrationDate || c.y.LastClassDay > _today) &&
                                        c.y.YearQuarterID != _yrqMax)
                                 .OrderBy(c => c.y.YearQuarterID)
                                 .Take(_quarterCount)
                                 .Any(c => c.y.YearQuarterID == s.YearQuarterID);
                    }

                    return(filter);
                }

                throw new ArgumentNullException("dbContext", "Not a valid ODS database context");
            }

            throw new ArgumentNullException("dbContext", "Not a valid database context");
        }
コード例 #6
0
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <param name="dbContext"></param>
        /// <remarks>
        /// This property assumes the database field is 2 characters long.
        /// </remarks>
        /// <exception cref="InvalidOperationException">A valid <see cref="Options"/> value was not specified when the class was instantiated.</exception>
        /// <seealso cref="Options"/>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            string onlineFlag     = _settings.ClassFlags.Online;
            string hybridFlag     = _settings.ClassFlags.Hybrid;
            string telecourseFlag = _settings.ClassFlags.Telecourse;

            if (_option == Options.All)
            {
                return(s => true);
            }

            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    // Construct a list of ClassIDs that match the specified modality/ies...
                    IQueryable <SectionEntity> includes = db.Sections.Where(s => false).Select(s => s);                         // hack to produce a valid, but empty collection

                    if ((_option & Options.Online) == Options.Online)
                    {
                        includes = includes.Union(db.Sections.Where(i => i.SBCTCMisc1.StartsWith(onlineFlag)).Select(i => i));
                    }
                    if ((_option & Options.Hybrid) == Options.Hybrid)
                    {
                        includes = includes.Union(db.Sections.Where(i => i.SBCTCMisc1.StartsWith(hybridFlag)).Select(i => i));
                    }
                    if ((_option & Options.Telecourse) == Options.Telecourse)
                    {
                        includes = includes.Union(db.Sections.Where(i => i.SBCTCMisc1.StartsWith(telecourseFlag)).Select(i => i));
                    }
                    if ((_option & Options.OnCampus) == Options.OnCampus)
                    {
                        includes = includes.Union(db.Sections.Where(i => i.SBCTCMisc1 == null || (!i.SBCTCMisc1.StartsWith(onlineFlag) && !i.SBCTCMisc1.StartsWith(hybridFlag) && !i.SBCTCMisc1.StartsWith(telecourseFlag))).Select(i => i));
                    }

                    // ... and then filter by that list
                    return(s => includes.Any(i => i.ClassID == s.ClassID));
                }

                throw new ArgumentNullException("dbContext", "Database context is not valid.");
            }

            throw new ArgumentNullException("dbContext", "Database context is null.");
        }
コード例 #7
0
        /// <summary>
        /// Provides the appropriate anonymous method for a LINQ .Where() call, depending on the option specified
        /// </summary>
        /// <param name="dbContext"></param>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (dbContext != null)
            {
                OdsContext db = dbContext as OdsContext;

                if (db != null)
                {
                    return(s => s.StartDate.HasValue &&
                           SqlFunctions.DateAdd("day", (_days * -1), s.StartDate) >= db.YearQuarters.Where(y => y.YearQuarterID == s.YearQuarterID)
                           .Select(y => y.FirstClassDay)
                           .FirstOrDefault());
                }

                throw new ArgumentNullException("dbContext", "Database context is not valid.");
            }

            throw new ArgumentNullException("dbContext", "Database context is null.");
        }
コード例 #8
0
        /// <summary>
        /// Gets filter to only include <see cref="Section"/>s which are "available"
        /// </summary>
        /// <param name="dbContext"></param>
        /// <remarks>
        /// An "available" <see cref="Section"/> is currently defined as:
        /// <list type="bullet">
        ///		<item>
        ///			<description>
        ///			<b>Normal Section:</b> <i>ClassCapacity</i> - <i>StudentsEnrolled</i>
        ///			</description>
        ///		</item>
        ///		<item>
        ///			<description>
        ///			<b>Clustered Section:</b> max(<i>ClusterCapacity</i>) - sum(<i>StudentsEnrolled</i>)
        ///			</description>
        ///		</item>
        ///		<item>
        ///			<description>
        ///			<b>And</b> Does not have a <see cref="OdsContext.WaitListCounts">Waitlist</see>
        ///			</description>
        ///		</item>
        /// </list>
        ///
        /// NOTE: If these rules do not match the logic needed by your school, create a custom "availability" <see cref="ISectionFacet">Facet</see> to use instead.
        ///
        /// </remarks>
        /// <exception cref="ArgumentNullException"><paramref name="dbContext"/>Is null, or is not a valid <see cref="OdsContext"/></exception>
        public Expression <Func <T, bool> > GetFilter <T>(DbContext dbContext) where T : SectionEntity
        {
            if (_options == Options.Open)
            {
                if (dbContext != null)
                {
                    OdsContext db = dbContext as OdsContext;

                    if (db != null)
                    {
                        return(s => db.Sections.Where(section => section.ClusterItemNumber != null)
                               .GroupBy(section => section.ClassID, section => section, (id, sec) => new
                        {
                            ClassID = id,
                            Capacity = sec.Max(c => c.ClusterCapacity),
                            Enrolled = sec.Sum(c => c.StudentsEnrolled)
                        })
                               .Where(cluster => (cluster.Capacity - cluster.Enrolled) > 0)
                               .Select(section => section.ClassID)
                               .Union(
                                   db.Sections.Where(sect => sect.ClusterItemNumber == null)
                                   .Where(sect => sect.ClassCapacity - sect.StudentsEnrolled > 0)
                                   .Select(sect => sect.ClassID)
                                   )
                               .Where(id => !db.WaitListCounts.Where(w => w.Status == _waitlistStatus).Select(w => w.ClassID).Contains(id))
                               .Contains(s.ClassID));
                    }

                    throw new ArgumentNullException("dbContext", "Not a valid ODS database context");
                }

                throw new ArgumentNullException("dbContext", "Not a valid database context");
            }

            return(s => true);                  // accept all records
        }
コード例 #9
0
        // TODO: look at IMSInterchange mapper
        // how can we define expected methods, but not expose them externally??

        ///<summary>
        ///
        ///</summary>
        ///<param name="db"></param>
        ///<returns></returns>
        internal IList <Section> GetData(OdsContext db)
        {
            throw new NotImplementedException();
        }