public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notifications.Notification>();

                var query = repository.Notifications;

                if (!string.IsNullOrEmpty(criteria.ObjectId))
                {
                    query = query.Where(n => n.ObjectId == criteria.ObjectId);
                }
                if (!string.IsNullOrEmpty(criteria.ObjectTypeId))
                {
                    query = query.Where(n => n.ObjectTypeId == criteria.ObjectTypeId);
                }

                if (criteria.IsActive)
                {
                    query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddHours(n.LastFailAttemptDate, criteria.RepeatHoursIntervalForFail) < DateTime.UtcNow) &&
                                        (n.StartSendingDate == null || n.StartSendingDate < DateTime.UtcNow));
                }
                retVal.TotalCount    = query.Count();
                retVal.Notifications = query.OrderBy(n => n.CreatedDate)
                                       .Skip(criteria.Skip)
                                       .Take(criteria.Take)
                                       .ToArray()
                                       .Select(x => GetNotificationCoreModel(x))
                                       .ToList();
            }

            return(retVal);
        }
示例#2
0
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notification.Notification>();
                if (!criteria.IsActive)
                {
                    var notifications = repository.Notifications.Where(n => n.ObjectId == criteria.ObjectId && n.ObjectTypeId == criteria.ObjectTypeId).OrderBy(n => n.CreatedDate).Skip(criteria.Skip).Take(criteria.Take);
                    foreach (var notification in notifications)
                    {
                        retVal.Notifications.Add(GetNotificationCoreModel(notification));
                    }
                    retVal.TotalCount = repository.Notifications.Count(n => n.ObjectId == criteria.ObjectId && n.ObjectTypeId == criteria.ObjectTypeId);
                }
                else
                {
                    var notifications = repository.Notifications.Where(n => n.IsActive && !n.IsSuccessSend && !n.SentDate.HasValue && (!n.StartSendingDate.HasValue || (n.StartSendingDate.HasValue && n.StartSendingDate.Value < DateTime.UtcNow))).OrderBy(n => n.CreatedBy).Take(criteria.Take);
                    foreach (var notification in notifications)
                    {
                        retVal.Notifications.Add(GetNotificationCoreModel(notification));
                    }
                }
            }

            return(retVal);
        }
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Core.Notification.Notification>();
                var notifications = repository.Notifications.Take(criteria.Take).Skip(criteria.Skip);
                foreach (var notification in notifications)
                {
                    retVal.Notifications.Add(GetNotificationCoreModel(notification));
                }
                retVal.TotalCount = notifications.Count();
            }

            return(retVal);
        }
        public async Task <SearchNotificationsResult> Search(SearchNotificationsParameter parameter)
        {
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }

            IQueryable <Models.Notification> notifications = _context.Notifications.Include(n => n.Parameters);

            if (!string.IsNullOrWhiteSpace(parameter.From))
            {
                notifications = notifications.Where(n => n.From == parameter.From);
            }

            if (!string.IsNullOrWhiteSpace(parameter.To))
            {
                notifications = notifications.Where(n => n.To == parameter.To);
            }

            if (parameter.StartDateTime != null)
            {
                notifications = notifications.Where(n => n.CreatedDateTime >= parameter.StartDateTime);
            }

            if (parameter.EndDateTime != null)
            {
                notifications = notifications.Where(n => n.CreatedDateTime <= parameter.EndDateTime);
            }

            if (parameter.IsRead != null)
            {
                notifications = notifications.Where(n => n.IsRead == parameter.IsRead);
            }

            notifications = notifications.OrderByDescending(n => n.CreatedDateTime);
            var result = new SearchNotificationsResult
            {
                TotalResults = await notifications.CountAsync().ConfigureAwait(false),
                StartIndex   = parameter.StartIndex
            };

            notifications  = notifications.Skip(parameter.StartIndex).Take(parameter.Count);
            result.Content = await notifications.Select(c => c.ToAggregate()).ToListAsync().ConfigureAwait(false);

            return(result);
        }
        public SearchNotificationsResult SearchNotifications(SearchNotificationCriteria criteria)
        {
            var retVal = new SearchNotificationsResult();

            using (var repository = _repositoryFactory())
            {
                retVal.Notifications = new List <Notification>();

                var query = repository.Notifications;

                if (!string.IsNullOrEmpty(criteria.ObjectId))
                {
                    query = query.Where(n => n.ObjectId == criteria.ObjectId);
                }
                if (!string.IsNullOrEmpty(criteria.ObjectTypeId))
                {
                    query = query.Where(n => n.ObjectTypeId == criteria.ObjectTypeId);
                }

                if (criteria.IsActive)
                {
                    query = query.Where(n => n.IsActive && n.SentDate == null && (n.LastFailAttemptDate == null || DbFunctions.AddMinutes(n.LastFailAttemptDate, criteria.RepeatMinutesIntervalForFail) < DateTime.UtcNow) &&
                                        (n.StartSendingDate == null || n.StartSendingDate < DateTime.UtcNow));
                }
                retVal.TotalCount = query.Count();

                var sortInfos = criteria.SortInfos;
                if (sortInfos.IsNullOrEmpty())
                {
                    sortInfos = new[] { new SortInfo {
                                            SortColumn = "CreatedDate", SortDirection = SortDirection.Descending
                                        } };
                }
                query = query.OrderBySortInfos(sortInfos).ThenBy(x => x.Id);

                retVal.Notifications = query.Skip(criteria.Skip)
                                       .Take(criteria.Take)
                                       .ToArray()
                                       .Select(GetNotificationCoreModel)
                                       .ToList();
            }

            return(retVal);
        }