Exemplo n.º 1
0
        public static async Task <HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Anonymous, "delete")] HttpRequestData req,
                                                        FunctionContext executionContext)
        {
            var repositorio = new TarefaRepositorio();
            var okRetorno   = req.CreateResponse();
            var logger      = executionContext.GetLogger("Delete");

            logger.LogInformation("C# HTTP trigger function processed a request.");
            Tarefa tarefa = new();
            var    query  = System.Web.HttpUtility.ParseQueryString(req.Url.Query);
            var    value  = query["id"];

            if (value != null)
            {
                tarefa = repositorio.GetById(new Guid(value));
                if (tarefa != null)
                {
                    await repositorio.Remove(tarefa);

                    await okRetorno.WriteAsJsonAsync(new OkResult());
                }
                else
                {
                    okRetorno = req.CreateResponse(System.Net.HttpStatusCode.NotFound);
                }
            }
            else
            {
                okRetorno = req.CreateResponse(System.Net.HttpStatusCode.BadRequest);
            }



            return(okRetorno);
        }