public async Task <IEnumerable <Ingredient> > GetListAsync(ResourceParameters.Ingredients resourceParameters) { ParameterChecks.CheckResourceParameters(resourceParameters); var collection = _context.Ingredients.AsQueryable <Ingredient>(); if (!string.IsNullOrWhiteSpace(resourceParameters.SearchQuery)) { collection = collection.Where(i => i.Name.Contains(resourceParameters.SearchQuery.Trim())); } if (!string.IsNullOrWhiteSpace(resourceParameters.OrderBy)) { collection = resourceParameters.SortAsc ? collection.OrderBy(i => i.Name) : collection.OrderByDescending(i => i.Name); } return(await collection.Skip((resourceParameters.PageNumber - 1) *resourceParameters.PageSize).Take(resourceParameters.PageSize).ToListAsync()); }
public async Task <IEnumerable <Ingredient> > GetListAsync(ResourceParameters.Ingredients ingredientsResourceParameters) { return(await _dal.GetListAsync(ingredientsResourceParameters)); }
public async Task <ActionResult <IEnumerable <IngredientDto> > > GetIngredientsAsync([FromQuery] ResourceParameters.Ingredients ingredientsResourceParameters) { var ingredientEntities = await _ingredients.GetListAsync(ingredientsResourceParameters); var ingredientDtosList = _mapper.Map <IEnumerable <IngredientDto> >(ingredientEntities); return(Ok(ingredientDtosList)); }