public WatchlistFilterPaginatedSpecification(WatchlistFilterDto watchlistFilter)
            : base(x => (string.IsNullOrWhiteSpace(watchlistFilter.Title) || x.Title.ToLower().Contains(watchlistFilter.Title.ToLower())) &&
                   (watchlistFilter.UserId == null || x.UserId == watchlistFilter.UserId))
        {
            if (watchlistFilter.OrderByDescending == nameof(Domain.Entities.Watchlist.CreatedAt))
            {
                ApplyOrderByDescending(x => x.CreatedAt);
            }

            ApplyPaging(watchlistFilter.Skip, watchlistFilter.Take, watchlistFilter.PageNumber);
        }
示例#2
0
        public async Task <IEnumerable <WatchlistForListDto> > GetAll(WatchlistFilterDto watchlistFilter)
        {
            var watchlists = await _uow.Repository <Domain.Entities.Watchlist>().FindAsyncWithPagination(new WatchlistFilterPaginatedSpecification(watchlistFilter));

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

            var watchlistsToReturn = _mapper.Map <IEnumerable <WatchlistForListDto> >(watchlists);

            await _photoService.IncludeMainPhoto(watchlistsToReturn, (int)EntityTypes.Watchlist);

            return(watchlistsToReturn);
        }
    public async Task <ActionResult <IEnumerable <WatchlistDto> > > GetAsync([FromQuery] WatchlistFilterDto filter, int skip, int take)
    {
        string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

        if (userId == null)
        {
            throw new InvalidPermissionException(ErrorCode.InvalidUserId);
        }

        Expression <Func <Watchlist, bool> > expression = w =>
                                                          (string.IsNullOrEmpty(filter.Name) || w.Name.Contains(filter.Name)) &&
                                                          (string.IsNullOrEmpty(userId) || w.UserId == userId);

        var watchlists = await _manager.GetWatchlistsAsync(expression, skip, take);

        var watchlistDtos = _mapper.Map <IEnumerable <Watchlist>, IEnumerable <WatchlistDto> >(watchlists);

        return(watchlistDtos.ToList());
    }
示例#4
0
 public async Task <IActionResult> GetAll([FromQuery] WatchlistFilterDto watchlistFilter)
 {
     return(Ok(await _watchlistService.GetAll(watchlistFilter)));
 }