public static async Task <HttpResponseMessage> GetAll(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Funcionarios")] HttpRequest req,
            ILogger log, [Inject] IFuncionariosService funcionariosService)
        {
            try
            {
                log.LogInformation("Funcionarios_GetAll started a request.");

                var result = await funcionariosService.GetAll();

                string json = JsonConvert.SerializeObject(result);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(json, Encoding.UTF8, "application/json")
                });
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(ex.Message, Encoding.UTF8)
                });
            }
            finally
            {
                log.LogInformation("Funcionarios_GetAll finished a request.");
            }
        }
Esempio n. 2
0
 public IEnumerable <FuncionariosViewModel> GetAll()
 {
     return(Mapper.Map <IEnumerable <Funcionarios>, IEnumerable <FuncionariosViewModel> >(_funcionariosService.GetAll()));
 }