Esempio n. 1
0
        public async Task <PagedList <CoctailDto> > GetCoctailsAsync(string name, IList <string> ingredients, CoctailParams coctailParams)
        {
            var coctailsQueryable = _context.Coctails
                                    .Where(x => x.IsAccepted)
                                    .ProjectTo <CoctailDto>(_mapper.ConfigurationProvider)
                                    .AsQueryable();

            if (!string.IsNullOrEmpty(name))
            {
                coctailsQueryable = coctailsQueryable.Where(x => EF.Functions.Like(x.Name, $"%{name}%"));
            }

            var query = QueryBuilder.BuildIngredientsQuery(coctailsQueryable, ingredients);

            query = QueryBuilder.AddFiltersQuery(query, coctailParams);

            return(await PagedList <CoctailDto> .CreateAsync(query, coctailParams.PageNumber, coctailParams.PageSize));
        }
Esempio n. 2
0
        public async Task <ActionResult <IList <Coctail> > > GetCoctails(string name, [FromQuery] IList <string> ingredients, [FromQuery] CoctailParams coctailParams)
        {
            var coctails = await _coctailRepository.GetCoctailsAsync(name, ingredients, coctailParams);

            if (coctails != null)
            {
                Response.AddPaginationHeader(coctails.CurrentPage, coctails.PageSize, coctails.TotalCount, coctails.TotalPages);

                return(Ok(coctails));
            }

            return(NotFound("No cocktails found with the specified filters."));
        }