public static MobileCheckinRecordCache LoadById(int id)
        {
            MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(new RockContext());
            var record = mobileCheckinRecordService.Get(id);

            if (record == null || record.CreatedDateTime < Rock.RockDateTime.Today)
            {
                return(null);
            }

            var recordCache = new MobileCheckinRecordCache();

            recordCache.SetFromEntity(record);

            return(recordCache);
        }
        public static bool CancelReservation(MobileCheckinRecordCache record, bool cancelEvenIfNotExpired = false)
        {
            if (record.Status != MobileCheckinStatus.Active)
            {
                //We can't cancel a mobile record that is not active.
                return(false);
            }

            //Keeps us from accidentally pulling the rug out from under someone
            if (!cancelEvenIfNotExpired && record.ReservedUntilDateTime.HasValue && record.ReservedUntilDateTime.Value > Rock.RockDateTime.Now)
            {
                return(false);
            }

            using (RockContext rockContext = new RockContext())
            {
                MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext);
                AttendanceService          attendanceService          = new AttendanceService(rockContext);
                var mobileCheckinRecord = mobileCheckinRecordService.Get(record.Id);
                var attendances         = mobileCheckinRecord.Attendances.ToList();

                foreach (var attendance in attendances)
                {
                    attendance.EndDateTime      = Rock.RockDateTime.Now;
                    attendance.QualifierValueId = null;
                }

                mobileCheckinRecord.Status = MobileCheckinStatus.Canceled;

                rockContext.SaveChanges();
                attendances.ForEach(a => AttendanceCache.AddOrUpdate(a));
                Update(mobileCheckinRecord.Id);
            }

            return(true);
        }
        public MobileCheckinRecord GetEntity(RockContext rockContext)
        {
            MobileCheckinRecordService mobileCheckinRecordService = new MobileCheckinRecordService(rockContext);

            return(mobileCheckinRecordService.Get(Id));
        }