Esempio n. 1
0
        public async Task <IActionResult> Get(bool IncluirEnlacesHateOS = false, int numeroPagina = 1, int cantidad = 10)
        {
            //mamadas
            //ActionResult</*IEnumerable<AutorDTO>*/ColeccionDeRecursos<AutorDTO>>

            //throw new NotImplementedException();
            //logger.LogInformation("obteniendo los autores");
            //claseB.HacerAlgo();

            var query = context.Autores.AsQueryable();

            var totalRegistros = query.Count();

            var autores = await query.Skip(cantidad *(numeroPagina - 1)).Take(cantidad).ToListAsync();

            Response.Headers["X-Total-Registros"]  = totalRegistros.ToString();
            Response.Headers["X-Cantidad-Paginas"] = ((int)Math.Ceiling((double)totalRegistros / cantidad)).ToString();
            var autoresDTO = mapper.Map <List <AutorDTO> >(autores);

            var resultado = new ColeccionDeRecursos <AutorDTO>(autoresDTO);

            if (IncluirEnlacesHateOS)
            {
                autoresDTO.ForEach(s => GenerarEnlaces(s));
                resultado.Enlaces.Add(new Enlace(Url.Link("ObtenerAutores", new { }), rel: "self", metodo: "GET"));
                resultado.Enlaces.Add(new Enlace(Url.Link("CrearAutor", new { }), rel: "CreateAuthor", metodo: "POST"));
            }

            return(Ok(autoresDTO));
            //context.Autores.Include(x => x.Libros).ToList();
        }
Esempio n. 2
0
        public ColeccionDeRecursos <AutorDTO> GenerarEnlaces(List <AutorDTO> autores)
        {
            var resultado = new ColeccionDeRecursos <AutorDTO>(autores);

            autores.ForEach(a => GenerarEnlaces(a));
            resultado.Enlaces.Add(new Enlace(_urlHelper.Link("ObtenerAutores", new { }), rel: "self", metodo: "GET"));
            resultado.Enlaces.Add(new Enlace(_urlHelper.Link("CrearAutor", new { }), rel: "crear-autor", metodo: "POST"));
            return(resultado);
        }