public IPagedList <ProductReview> Search(ProductReviewSearchQuery query) { IQueryOver <ProductReview, ProductReview> queryOver = _session.QueryOver <ProductReview>(); switch (query.ApprovalStatus) { case ApprovalStatus.Pending: queryOver = queryOver.Where(review => review.Approved == null); break; case ApprovalStatus.Rejected: queryOver = queryOver.Where(review => review.Approved == false); break; case ApprovalStatus.Approved: queryOver = queryOver.Where(review => review.Approved == true); break; } if (!string.IsNullOrWhiteSpace(query.ProductName)) { ProductVariant productVariantAlias = null; Product productAlias = null; queryOver = queryOver.JoinAlias(review => review.ProductVariant, () => productVariantAlias) .JoinAlias(() => productVariantAlias.Product, () => productAlias) .Where( () => productVariantAlias.Name.IsInsensitiveLike(query.ProductName, MatchMode.Anywhere) || productAlias.Name.IsInsensitiveLike(query.ProductName, MatchMode.Anywhere)); } if (!string.IsNullOrWhiteSpace(query.Email)) { User userAlias = null; queryOver = queryOver.JoinAlias(review => review.User, () => userAlias, JoinType.LeftOuterJoin) .Where( review => (review.Email.IsInsensitiveLike(query.Email, MatchMode.Anywhere)) || (userAlias.Email.IsInsensitiveLike(query.Email, MatchMode.Anywhere))); } if (!string.IsNullOrWhiteSpace(query.Title)) { queryOver = queryOver.Where(review => review.Title.IsLike(query.Title, MatchMode.Anywhere)); } if (query.DateFrom.HasValue) { queryOver = queryOver.Where(review => review.CreatedOn >= query.DateFrom); } if (query.DateTo.HasValue) { queryOver = queryOver.Where(review => review.CreatedOn < query.DateTo); } return (queryOver.OrderBy(review => review.Approved) .Asc.ThenBy(review => review.CreatedOn) .Desc.Paged(query.Page)); }
public ViewResult Index(ProductReviewSearchQuery searchQuery) { ViewData["approval-options"] = _productReviewAdminService.GetApprovalOptions(); ViewData["results"] = _productReviewAdminService.Search(searchQuery); return(View(searchQuery)); }