Пример #1
0
        public async Task <IActionResult> GetAllReviews([FromQuery] ReviewRequestParametersDto req, [FromRoute] Guid experienceId)
        {
            // get all the reviews that belong to an experience
            var allReviews = await _reviewRepository.GetAllReviewsAsync(req, experienceId);

            // map it to the view DTO and return
            var listToReturn = _mapper.Map <IEnumerable <ViewReviewDto> >(allReviews);

            return(Ok(listToReturn));
        }
Пример #2
0
        /// <summary>
        /// Gets all reviews of an experience in the database, in a paged order,
        /// by the experience id
        /// </summary>
        /// <param name="req">Filtering  and searching parameters</param>
        /// <param name="experienceId">Id of the experience to get reviews for</param>
        public async Task <IEnumerable <Review> > GetAllReviewsAsync(ReviewRequestParametersDto req, Guid experienceId)
        {
            var query = this._context.Reviews.Where(x => x.ExperienceId == experienceId).AsQueryable().AsNoTracking();

            if (!(req.FilterByDate == DateTime.MinValue))
            {
                query = query.Where(x => x.CreatedOn.Date.Equals(req.FilterByDate));
            }
            if (!string.IsNullOrEmpty(req.FilterByOwner))
            {
                query = query.Where(x => x.Creator.FirstName.ToLower() == req.FilterByOwner.ToLower())
                        .Where(x => x.Creator.LastName.ToLower() == req.FilterByOwner.ToLower());
            }
            if (!string.IsNullOrEmpty(req.SearchString))
            {
                query = query.Where(x => x.Description.ToLower().Contains(req.SearchString.ToLower()));
            }
            return(await PaginatedList <Review> .CreateAsync(query, req.Page, req.PageSize));
        }