public IPagedList<Notification> Search(NotificationSearchQuery searchQuery)
        {
            var queryOver = _session.QueryOver<Notification>();

            if (!string.IsNullOrWhiteSpace(searchQuery.Message))
            {
                queryOver =
                    queryOver.Where(
                        notification => notification.Message.IsInsensitiveLike(searchQuery.Message, MatchMode.Anywhere));
            }
            if (searchQuery.UserId.HasValue)
            {
                queryOver = queryOver.Where(notification => notification.User.Id == searchQuery.UserId);
            }
            if (searchQuery.From.HasValue)
            {
                queryOver = queryOver.Where(notification => notification.CreatedOn >= searchQuery.From);
            }
            if (searchQuery.To.HasValue)
            {
                queryOver = queryOver.Where(notification => notification.CreatedOn <= searchQuery.To);
            }
            if (searchQuery.NotificationType.HasValue)
            {
                queryOver =
                    queryOver.Where(notification => notification.NotificationType == searchQuery.NotificationType);
            }

            return queryOver.OrderBy(notification => notification.CreatedOn).Desc.Paged(searchQuery.Page);
        }
Beispiel #2
0
 public ViewResult Index(NotificationSearchQuery searchQuery)
 {
     ViewData["results"] = _service.Search(searchQuery);
     ViewData["notification-type-options"] = _service.GetNotificationTypeOptions(true);
     return View(searchQuery);
 }