/// <summary>
        /// Implements <see cref="IStatisticsService.GetBySection(int)"/>.
        /// </summary>
        public IEnumerable <IdentityDTO> GetCurrentBySection(int section)
        {
            List <IdentityDTO> identities      = new List <IdentityDTO>();
            IdentityService    identityService = new IdentityService(Database, SyncDatabase);

            foreach (var identity in Database.Identity.GetAll())
            {
                int count = 0;
                var type  = Database.Type.GetAll().Where(x => x.Status.Equals("Статистический")).FirstOrDefault();
                foreach (var checkpoint in Database.Checkpoint.GetAll().Where(y => y.Section == section && y.Type != type))
                {
                    var activities = Database.Activity.GetAll().Where(x => x.IdentityGUID.Equals(identity.GUID) && x.CheckpointIP.Equals(checkpoint.IP));
                    if (activities != null)
                    {
                        count += activities.ToList().Count;
                    }
                }
                if (count % 2 != 0)
                {
                    identities.Add(identityService.GetFull(identity.GUID));
                }
            }
            return(identities);
        }
        /// <summary>
        /// Implements <see cref="IStatisticsService.GetBySection(int, DateTime, DateTime)"/>.
        /// </summary>
        public IEnumerable <ActivityDTO> GetBySection(int section, DateTime start, DateTime end)
        {
            List <ActivityDTO> activities        = new List <ActivityDTO>();
            IdentityService    identityService   = new IdentityService(Database, SyncDatabase);
            CheckpointService  checkpointService = new CheckpointService(Database);

            foreach (var checkpoint in Database.Checkpoint.GetAll().Where(y => y.Section == section))
            {
                foreach (var activity in Database.Activity.GetAll().Where(x => x.CheckpointIP ==
                                                                          checkpoint.IP && x.Date > start && x.Date <= end))
                {
                    activities.Add(new ActivityDTO()
                    {
                        ID         = activity.ID,
                        User       = identityService.GetFull(activity.IdentityGUID),
                        Checkpoint = checkpointService.GetByIP(activity.CheckpointIP),
                        Mode       = Database.Mode.GetAll().Where(x => x.ID == activity.ID).FirstOrDefault(),
                        Date       = activity.Date,
                        Status     = activity.Status
                    });
                }
            }
            return(activities);
        }
        /// <summary>
        /// Implements <see cref="IStatisticsService.GetStatistics(int?, int?, int?, string, string, string, DateTime?, DateTime?)"/>.
        /// </summary>
        public IEnumerable <IdentityDTO> GetStatistics(int?campus, int?row, int?classroom, string name, string midname, string surname, DateTime?start, DateTime?end)
        {
            Dictionary <string, IdentityDTO> activityDTOs = new Dictionary <string, IdentityDTO>();
            IdentityService identityService = new IdentityService(Database, SyncDatabase);

            //CheckpointService checkpointService = new CheckpointService(Database);

            if (start == (new DateTime(1900, 1, 1, 0, 0, 0)))
            {
                foreach (var identity in Database.Identity.GetAll())
                {
                    int count = 0;
                    foreach (var checkpoint in Database.Checkpoint.GetAll().Where(
                                 y =>
                                 (y.Campus.Equals(campus) || campus == 0) &&
                                 (y.Row.Equals(row) || row == 0) &&
                                 (y.Classroom.Equals(classroom) || classroom == 0)
                                 ))
                    {
                        var activities = Database.Activity.GetAll().Where(x => x.IdentityGUID.Equals(identity.GUID) && x.CheckpointIP.Equals(checkpoint.IP));
                        if (activities != null)
                        {
                            count += activities.ToList().Count;
                        }
                    }
                    if (count % 2 != 0)
                    {
                        if (!activityDTOs.ContainsKey(identity.GUID))
                        {
                            var full = identityService.GetFull(identity.GUID);
                            if (name == null || (full.Name + " " + full.Surname + " " + full.Midname).IndexOf(name, StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                activityDTOs.Add(identity.GUID, full);
                            }
                        }
                    }
                }
            }
            else
            {
                foreach (var checkpoint in Database.Checkpoint.GetAll().Where((
                                                                                  y =>
                                                                                  (y.Campus.Equals(campus) || campus == 0) &&
                                                                                  (y.Row.Equals(row) || row == 0) &&
                                                                                  (y.Classroom.Equals(classroom) || classroom == 0)
                                                                                  )))
                {
                    var abs = Database.Activity.GetAll();
                    foreach (var activity in
                             abs.SelectMany(a =>
                                            abs.Where(x => x.CheckpointIP == checkpoint.IP &&
                                                      (x.Date > start || true) && (x.Date <= end || true)))
                             .GroupBy(z => z.IdentityGUID)
                             .Select(z => z.First())
                             .ToList())
                    {
                        if (!activityDTOs.ContainsKey(activity.IdentityGUID))
                        {
                            var identity = identityService.GetFull(activity.IdentityGUID);
                            if (name == null || (identity.Name + " " + identity.Surname + " " + identity.Midname).IndexOf(name, StringComparison.CurrentCultureIgnoreCase) != -1)
                            {
                                activityDTOs.Add(activity.IdentityGUID, identity);
                            }
                        }
                    }
                }
            }

            return(activityDTOs.Values.ToList());
        }