Advertisement
joaopaulofcc

Untitled

Sep 22nd, 2021
691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Microsoft.EntityFrameworkCore;
  8. using projetoTeste.Models;
  9.  
  10. namespace projetoTeste.Controllers
  11. {
  12.     [Route("[controller]/[action]")]
  13.     [ApiController]
  14.     public class ColaboradorController : ControllerBase
  15.     {
  16.         private BDContexto contexto;
  17.        
  18.         public ColaboradorController(BDContexto bdContexto)
  19.         {
  20.             contexto = bdContexto;
  21.         }
  22.        
  23.         [HttpGet]
  24.         public List<Colaborador> Listar()
  25.         {
  26.             return contexto.Colaborador.Include(c => c.IdCargoNavigation).OrderBy(c => c.Nome).Select
  27.             (
  28.                 c => new Colaborador
  29.                 {
  30.                     Id = c.Id,
  31.                     Nome = c.Nome,
  32.                     Salario = c.Salario,
  33.                     IdCargoNavigation = new Cargo
  34.                     {
  35.                         Id = c.IdCargoNavigation.Id,
  36.                         Nome = c.IdCargoNavigation.Nome,
  37.                         Tipo = c.IdCargoNavigation.Tipo,
  38.                         SalarioMinimo = c.IdCargoNavigation.SalarioMinimo,
  39.                         SalarioMaximo = c.IdCargoNavigation.SalarioMaximo
  40.                     }
  41.                 }).ToList();
  42.         }
  43.  
  44.         [HttpGet]
  45.         public List<Colaborador> ListarPorFaixa(double valorInicial, double valorFinal)
  46.         {
  47.             return contexto.Colaborador.Where(c => c.Salario >= valorInicial && c.Salario <= valorFinal).Select
  48.             (
  49.                 c => new Colaborador
  50.                 {
  51.                     Id = c.Id,
  52.                     Nome = c.Nome,
  53.                     Salario = c.Salario,
  54.                     IdCargoNavigation = new Cargo
  55.                     {
  56.                         Id = c.IdCargoNavigation.Id,
  57.                         Nome = c.IdCargoNavigation.Nome,
  58.                         Tipo = c.IdCargoNavigation.Tipo,
  59.                         SalarioMinimo = c.IdCargoNavigation.SalarioMinimo,
  60.                         SalarioMaximo = c.IdCargoNavigation.SalarioMaximo                    
  61.                     }
  62.                 }).ToList();
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement