예제 #1
0
        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.");
            }
        }
예제 #2
0
        public static async Task <HttpResponseMessage> AddorUpdate(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", "put", Route = "Funcionarios")] HttpRequest req,
            ILogger log, [Inject] IFuncionariosService funcionariosService)
        {
            try
            {
                log.LogInformation("Funcionarios_AddorUpdate started a request.");

                // Get request body
                string requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
                var    lFuncionario = JsonConvert.DeserializeObject <List <Funcionario> >(requestBody);
                if (lFuncionario == null || lFuncionario.Count == 0)
                {
                    throw new Exception("FuncionariosList Cannot be Empty");
                }

                bool result = await funcionariosService.AddOrUpdate(lFuncionario);

                if (result)
                {
                    return new HttpResponseMessage(HttpStatusCode.OK)
                           {
                               Content = new StringContent(lFuncionario.Count.ToString(), Encoding.UTF8, "application/json")
                           }
                }
                ;

                else
                {
                    throw new Exception("Firebase returned Unsucessfully status code");
                }
            }
            catch (Exception ex)
            {
                log.LogError(ex.Message);
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent(ex.Message, Encoding.UTF8)
                });
            }
            finally
            {
                log.LogInformation("Funcionarios_AddorUpdate finished a request.");
            }
        }
예제 #3
0
 public FuncionariosAppService(IFuncionariosService funcionariosService, ILogSistemaService logSistemaService)
 {
     _funcionariosService = funcionariosService;
     _logSistemaService   = logSistemaService;
 }