public async Task <List <Notification> > LoadWelcomeMessages(Preferences preferences, Guid userId)
        {
            var orderByCreationTimeDescending   = preferences.OrderByCreationTimeDescending;
            var thenOrderByImportancyDescending = preferences.OrderByImportancyDescending;
            var numberOfWelcomeMessages         = preferences.NumberOfWelcomeMessages;
            var importancy = preferences.MinimalImportancyLevel;

            var confirmationType = new ConfirmationTypePreferences
            {
                SeeRead   = preferences.SeeReadNotifications,
                SeeUnread = preferences.SeeUnreadNotifications
            };

            var notificationsQuery = _queryBuilder
                                     .WithQueriesAndUser(GetNotificationQuery(), userId)
                                     .FilterByConfirmationType(confirmationType)
                                     .FilterByMinimalImportancy(importancy)
                                     .OrderByCreationDate(orderByCreationTimeDescending)
//                .ThenOrderByState()
//                .ThenOrderByImportancy(thenOrderByImportancyDescending)
                                     .Take(numberOfWelcomeMessages)
                                     .Build();

            await notificationsQuery.ForEachAsync(notification => notification.IncrementProcessedTimes());

            await _context.SaveChangesAsync();

            var notifications = notificationsQuery.ToList();

            return(notifications);
        }
Esempio n. 2
0
        public INotificationQueryBuilder FilterByConfirmationType(
            ConfirmationTypePreferences confirmationTypePreferences)
        {
            if (confirmationTypePreferences.SeeRead && confirmationTypePreferences.SeeUnread)
            {
                _query = _query.Where(NotAcquiredOrAnyFromReadOrUnread(_userId));
            }
            else if (confirmationTypePreferences.SeeRead)
            {
                _query = _query.Where(NotAcquiredOrAnyFromRead(_userId));
            }
            else if (confirmationTypePreferences.SeeUnread)
            {
                _query = _query.Where(NotAcquiredOrAnyFromUnread(_userId));
            }

            return(this);
        }