Example #1
0
        // Given offsets from the previous page perform a search with the correct skip and take to be efficient
        private async Task <(IEnumerable <NotificationBannerModel> results, int count)> SearchWithOffsetsAsync(
            INtbsSearchBuilder ntbsQueryable,
            ILegacySearchBuilder legacySqlQuery)
        {
            var(orderedNotificationIds, ntbsCount) = await _searchService.OrderAndPaginateQueryableAsync(
                ntbsQueryable,
                PaginationParameters,
                User);

            var ntbsNotifications = await _notificationRepository.GetNotificationBannerModelsByIdsAsync(orderedNotificationIds);

            var(legacyNotifications, legacyCount) = await _legacySearchService.SearchAsync(
                legacySqlQuery,
                (int)PaginationParameters.LegacyOffset,
                PaginationParameters.PageSize,
                User);

            var allPossibleNotifications = ntbsNotifications.Concat(legacyNotifications);
            var permittedTbServiceCodes  = (await _userService.GetTbServicesAsync(User)).Select(s => s.Code);

            var notifications = allPossibleNotifications
                                .OrderByDescending(n => permittedTbServiceCodes.Contains(n.TbServiceCode))
                                .ThenByDescending(n => n.NotificationStatus == NotificationStatus.Draft)
                                .ThenByDescending(n => n.SortByDate)
                                .ThenByDescending(n => n.NotificationId)
                                .Take(PaginationParameters.PageSize);

            return(notifications, ntbsCount + legacyCount);
        }
Example #2
0
        private async Task <(IList <NotificationBannerModel> results, int count)> SearchAsync(
            INtbsSearchBuilder ntbsQueryable,
            ILegacySearchBuilder legacySqlQuery)
        {
            IEnumerable <NotificationBannerModel> notificationsBannerModels;
            int count;

            if (PaginationParameters.LegacyOffset == null && PaginationParameters.NtbsOffset == null)
            {
                (notificationsBannerModels, count) = await SearchWithoutOffsetsAsync(ntbsQueryable, legacySqlQuery);
            }
            else
            {
                (notificationsBannerModels, count) = await SearchWithOffsetsAsync(ntbsQueryable, legacySqlQuery);
            }
            // notificationsToDisplay is ToList() to enumerate it so that the dynamic/notificationBannerModels from the migration database are mapped correctly
            // and we can successfully update properties on the models
            return(notificationsBannerModels.ToList(), count);
        }