Esempio n. 1
0
        public static async Task <HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestData req,
                                                        FunctionContext executionContext)
        {
            var logger = executionContext.GetLogger("Post");

            logger.LogInformation("C# HTTP trigger function processed a request.");

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            Tarefa obj         = JsonConvert.DeserializeObject <Tarefa>(requestBody);
            var    repositorio = new TarefaRepositorio();
            var    okRetorno   = req.CreateResponse();

            if (obj == null)
            {
                await okRetorno.WriteAsJsonAsync(new BadRequestObjectResult(new { message = "Dados para criação de uma tarefa é obrigatoria" }));
            }
            else
            {
                obj.Id       = Guid.NewGuid();
                obj.DtCreate = DateTime.UtcNow;
                await repositorio.Save(obj);

                await okRetorno.WriteAsJsonAsync(new CreatedResult("", obj));
            }

            return(okRetorno);
        }