Ejemplo n.º 1
0
 private static SimplePredicate FilterUsers(ReviewFilterDto filter)
 {
     if (filter.UserID <= 0)
     {
         return(null);
     }
     return(new SimplePredicate(nameof(User), ValueComparingOperator.Equal, filter.UserID));
 }
Ejemplo n.º 2
0
        public ReviewWithUsersFilterPaginatedSpecification(ReviewFilterDto reviewFilter)
            : base(x => reviewFilter.FilmId == null || x.FilmId == reviewFilter.FilmId)
        {
            if (reviewFilter.OrderByDescending == nameof(Domain.Entities.Review.CreatedAt))
            {
                ApplyOrderByDescending(x => x.CreatedAt);
            }

            ApplyPaging(reviewFilter.Skip, reviewFilter.Take, reviewFilter.PageNumber);

            AddInclude($"{nameof(Domain.Entities.Review.User)}");
        }
Ejemplo n.º 3
0
        public async Task <IEnumerable <ReviewForListDto> > GetAll(ReviewFilterDto reviewFilter)
        {
            var reviews = await _uow.Repository <Domain.Entities.Review>().FindAsyncWithPagination(new ReviewWithUsersFilterPaginatedSpecification(reviewFilter));

            _context.HttpContext.Response.AddPagination(reviews.CurrentPage, reviews.PageSize, reviews.TotalCount, reviews.TotalPages);

            var reviewsToReturn = _mapper.Map <IEnumerable <ReviewForListDto> >(reviews);

            await _photoService.IncludeMainPhoto(reviewsToReturn.Select(x => x.User), (int)EntityTypes.User);

            return(reviewsToReturn);
        }
Ejemplo n.º 4
0
        private static CompositePredicate FilterEvaluations(ReviewFilterDto filter)
        {
            if (filter.Evaluation != null && filter.Evaluation.Any())
            {
                return(null);
            }

            var reviewsEvalPredicates = new List <IPredicate>(filter.Evaluation
                                                              .Select(eval => new SimplePredicate
                                                                          (nameof(Review.Evaluation),
                                                                          ValueComparingOperator.Equal,
                                                                          eval)));

            return(new CompositePredicate(reviewsEvalPredicates, LogicalOperator.OR));
        }
Ejemplo n.º 5
0
        protected override IQuery <Review> ApplyWhereClause(IQuery <Review> query, ReviewFilterDto filter)
        {
            var definedPredicates = new List <IPredicate>();

            AddIfDefined(FilterUsers(filter), definedPredicates);
            AddIfDefined(FilterEvaluations(filter), definedPredicates);
            if (definedPredicates.Count == 0)
            {
                return(query);
            }
            if (definedPredicates.Count == 1)
            {
                return(query.Where(definedPredicates.First()));
            }
            var wherePredicate = new CompositePredicate(definedPredicates);

            return(query.Where(wherePredicate));
        }
Ejemplo n.º 6
0
 public async Task <IActionResult> GetAll([FromQuery] ReviewFilterDto reviewFilter)
 {
     return(Ok(await _reviewService.GetAll(reviewFilter)));
 }