Ejemplo n.º 1
0
        public IEnumerable <RecipeVM> Get([FromQuery] AdminRecipeParameters parameters)
        {
            var adminRecipesFromService = _adminRecipeService.GetAllRecipes(parameters);

            var metadata = new
            {
                adminRecipesFromService.TotalCount,
                adminRecipesFromService.PageSize,
                adminRecipesFromService.CurrentPage,
                adminRecipesFromService.TotalPages,
                adminRecipesFromService.HasNext,
                adminRecipesFromService.HasPrevious
            };

            var list = adminRecipesFromService.Select(r => new RecipeVM
            {
                RecipeId     = r.RecipeId,
                Name         = r.Name,
                CategoryName = r.Category.Name,
                PublishedAt  = r.PublishedAt,
            }).ToList();

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));

            return(list);
        }
Ejemplo n.º 2
0
        public PagedList <Recipe> GetAllRecipes(AdminRecipeParameters adminRecipeParameters)
        {
            var xx = _db.Recipes
                     .Include(rcp => rcp.Ingredients)
                     .Include(rcp => rcp.MethodItems)
                     .Where(r => r.DeletedAt == null);

            var x = PagedList <Recipe> .ToPagedList(_db.Recipes
                                                    .Include(rcp => rcp.Category)
                                                    .Include(rcp => rcp.Ingredients)
                                                    .Include(rcp => rcp.MethodItems)
                                                    .Where(r => r.DeletedAt == null),
                                                    adminRecipeParameters.PageNumber,
                                                    adminRecipeParameters.PageSize);

            return(x);
        }