Rock.Model.AttendanceService.GetByDateAndLocation C# (CSharp) Méthode

GetByDateAndLocation() public méthode

Returns a queryable collection of Rock.Model.Attendance for a Rock.Model.Location on a specified date.
public GetByDateAndLocation ( System.DateTime date, int locationId ) : IQueryable
date System.DateTime A representing the date attended.
locationId int A representing the Id of the
Résultat IQueryable
        public IQueryable<Attendance> GetByDateAndLocation( DateTime date, int locationId )
        {
            DateTime beginDate = date.Date;
            DateTime endDate = beginDate.AddDays( 1 );

            return Queryable( "Group,Schedule,PersonAlias.Person" )
                .Where( a =>
                    a.StartDateTime >= beginDate &&
                    a.StartDateTime < endDate &&
                    !a.EndDateTime.HasValue &&
                    a.LocationId == locationId &&
                    a.DidAttend.HasValue &&
                    a.DidAttend.Value );
        }

Usage Example

        /// <summary>
        /// Reads the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public static KioskLocationAttendance Read( int id )
        {
            string cacheKey = KioskLocationAttendance.CacheKey( id );

            ObjectCache cache = MemoryCache.Default;
            KioskLocationAttendance locationAttendance = cache[cacheKey] as KioskLocationAttendance;

            if ( locationAttendance != null )
            {
                return locationAttendance;
            }
            else
            {
                var rockContext = new Rock.Data.RockContext();
                var location = new LocationService(rockContext).Get( id );
                if ( location != null )
                {
                    locationAttendance = new KioskLocationAttendance();
                    locationAttendance.LocationId = location.Id;
                    locationAttendance.LocationName = location.Name;
                    locationAttendance.Groups = new List<KioskGroupAttendance>();

                    var attendanceService = new AttendanceService(rockContext);
                    foreach ( var attendance in attendanceService.GetByDateAndLocation( RockDateTime.Today, location.Id ) )
                    {
                        AddAttendanceRecord( locationAttendance, attendance );
                    }

                    var cachePolicy = new CacheItemPolicy();
                    cachePolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds( 60 );
                    cache.Set( cacheKey, locationAttendance, cachePolicy );

                    return locationAttendance;
                }
            }

            return null;
        }
All Usage Examples Of Rock.Model.AttendanceService::GetByDateAndLocation