예제 #1
0
        public void Cleanup()
        {
            using (var rockContext = new RockContext())
            {
                var acService         = new AttendanceCodeService(rockContext);
                var attendanceService = new AttendanceService(rockContext);

                DateTime today       = RockDateTime.Today;
                DateTime tomorrow    = today.AddDays(1);
                var      todaysCodes = acService.Queryable()
                                       .Where(c => c.IssueDateTime >= today && c.IssueDateTime < tomorrow)
                                       .ToList();
                if (todaysCodes.Any())
                {
                    var ids = todaysCodes.Select(c => c.Id).ToList();

                    // get the corresponding attendance records and delete them first.
                    var todayTestAttendance = attendanceService.Queryable().Where(a => ids.Contains(a.AttendanceCodeId.Value));
                    if (todayTestAttendance.Any())
                    {
                        attendanceService.DeleteRange(todayTestAttendance);
                    }
                    acService.DeleteRange(todaysCodes);
                    rockContext.SaveChanges();
                }
            }
            AttendanceCodeService.FlushTodaysCodes();
        }
예제 #2
0
        /// <summary>
        /// Deletes the test data added to the database for each tests.
        /// </summary>
        private void Cleanup()
        {
            using (var rockContext = new RockContext())
            {
                var service = new AttendanceCodeService(rockContext);

                DateTime today       = RockDateTime.Today;
                DateTime tomorrow    = today.AddDays(1);
                var      todaysCodes = service.Queryable()
                                       .Where(c => c.IssueDateTime >= today && c.IssueDateTime < tomorrow)
                                       .ToList();
                if (todaysCodes.Any())
                {
                    service.DeleteRange(todaysCodes);
                    rockContext.SaveChanges();
                }
            }
            AttendanceCodeService.FlushTodaysCodes();
        }