Ejemplo n.º 1
0
        public List <Book> BuscarLivros(FiltrosDto filtros)
        {
            var livros = _repo.Query();

            if (!string.IsNullOrEmpty(filtros.Autor))
            {
                livros = livros.Where(p => p.Specifications.Author.Contains(filtros.Autor)).ToList();
            }

            if (!string.IsNullOrEmpty(filtros.NomeLivro))
            {
                livros = livros.Where(p => p.Name.Contains(filtros.NomeLivro)).ToList();
            }

            if (filtros.PrecoInicial != null)
            {
                livros = livros.Where(p => p.Price >= filtros.PrecoInicial).ToList();
            }

            if (filtros.PrecoFinal != null)
            {
                livros = livros.Where(p => p.Price <= filtros.PrecoFinal).ToList();
            }

            if (!string.IsNullOrEmpty(filtros.Genero))
            {
                livros = livros.Where(p => p.Specifications.Genres.Contains(filtros.Genero)).ToList();
            }

            if (filtros.OrdenacaoAscendente == OrdenacaoAscendente)
            {
                livros = livros.OrderBy(p => p.Price).ToList();
            }

            if (filtros.OrdenacaoDescendente == OrdenacaoDescendente)
            {
                livros = livros.OrderByDescending(p => p.Price).ToList();
            }

            if (!string.IsNullOrEmpty(filtros.Ilustrador))
            {
                livros = livros.Where(p => p.Specifications.Illustrator.Contains(filtros.Ilustrador)).ToList();
            }

            if (filtros.QuantidadePaginasInicial != null)
            {
                livros = livros.Where(p => p.Specifications.PageCount >= filtros.QuantidadePaginasInicial).ToList();
            }

            if (filtros.QuantidadePaginasFinal != null)
            {
                livros = livros.Where(p => p.Specifications.PageCount <= filtros.QuantidadePaginasFinal).ToList();
            }

            return(livros);
        }
Ejemplo n.º 2
0
        public IActionResult Get([FromQuery] FiltrosDto filtro)
        {
            var validacao = validator.Validate(filtro);

            if (!validacao.IsValid)
            {
                return(BadRequest(validacao.Errors));
            }

            return(Ok(new string[] { "value1", "value2" }));
        }
 public FiltroDtoValidatorTest()
 {
     validator = new FiltroDtoValidator();
     filtro    = new FiltrosDto()
     {
         Nome        = "Nome qualquer",
         DataInicial = DateTime.Now.AddDays(-30),
         DataFinal   = DateTime.Now,
         Codigo      = "1234567890123"
     };
 }
Ejemplo n.º 4
0
        public IEnumerable <Book> Get([FromQuery] string autor, [FromQuery] string nomelivro,
                                      [FromQuery] double?precoinicial, [FromQuery] double?precofinal,
                                      [FromQuery] string genero, [FromQuery] string ilustrador,
                                      [FromQuery] int?quantidadepaginasinicial, [FromQuery] int?quantidadepaginasfinal,
                                      [FromQuery] string ordenacaoascendente, [FromQuery] string ordenacaodescendente)
        {
            var filtros = new FiltrosDto
            {
                Autor                    = autor,
                NomeLivro                = nomelivro,
                Genero                   = genero,
                Ilustrador               = ilustrador,
                PrecoInicial             = precoinicial,
                PrecoFinal               = precofinal,
                QuantidadePaginasInicial = quantidadepaginasinicial,
                QuantidadePaginasFinal   = quantidadepaginasfinal,
                OrdenacaoAscendente      = ordenacaoascendente,
                OrdenacaoDescendente     = ordenacaodescendente
            };

            return(_service.BuscarLivros(filtros));
        }
Ejemplo n.º 5
0
 public IActionResult FiltrarViajes([FromBody] FiltrosDto dto)
 {
     try
     {
         var response = this.genericRepo.GetAll().ToList();
         if (dto.Origen != null)
         {
             response = response.Where(v => v.Origen == dto.Origen).ToList();
         }
         if (dto.Destino != null)
         {
             response = response.Where(v => v.Destino == dto.Destino).ToList();
         }
         if (dto.Fecha != null)
         {
             response = response.Where(v => v.DiasDeViaje.All(dv => dv.fechaDeViaje == dto.Fecha)).ToList();
         }
         return(Ok(response));
     }
     catch (Exception)
     {
         return(BadRequest("Hubo un error al listar preguntas"));
     }
 }