public static KioskLocationAttendance Read( int id )
{
string cacheKey = KioskLocationAttendance.CacheKey( id );
ObjectCache cache = Rock.Web.Cache.RockMemoryCache.Default;
KioskLocationAttendance locationAttendance = cache[cacheKey] as KioskLocationAttendance;
if ( locationAttendance != null )
{
return locationAttendance;
}
else
{
using ( 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.AddMinutes( 2 );
cache.Set( cacheKey, locationAttendance, cachePolicy );
return locationAttendance;
}
}
}
return null;
}