Exemplo n.º 1
0
        public PaginatedItems <Alarm> GetByDevice(string deviceId, IMongoFilter <Device, Alarm> filter, int rowsPerPage, int pageNumber)
        {
            DeviceAlarmFilter alarmFilter = new DeviceAlarmFilter
            {
                Context   = (filter as AlarmFilter).Context,
                AlarmType = (filter as AlarmFilter).AlarmType,
                Gravity   = (filter as AlarmFilter).Gravity,
                DeviceId  = deviceId,
                IsRead    = (filter as AlarmFilter).IsRead,
                IsActive  = (filter as AlarmFilter).IsActive
            };

            var totalCount = alarmRepository.CountByDevice(deviceId, alarmFilter);
            var pageCount  = rowsPerPage == 0 ? 1 : (int)Math.Ceiling((double)totalCount / rowsPerPage);

            return(new PaginatedItems <Alarm>
            {
                PageCount = pageCount,
                TotalItemsCount = totalCount,
                Items = alarmRepository.GetByDevice(deviceId, alarmFilter, rowsPerPage, pageNumber)
            });
        }