public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "Delete", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("DeleteTodoList Invoked."); string id = req.GetQueryNameValuePairs() .First(q => string.Compare(q.Key, "id", StringComparison.OrdinalIgnoreCase) == 0) .Value; log.Info($"DeleteTodoList Id: {id}."); TableEntity item = new TableEntity("todovue", id) { ETag = "*" //By default, the SDK enforces optimistic concurrency via ETags. Set this value to '*' in order to force an overwrite to an entity as part of an update operation. }; TableOperation operation = TableOperation.Delete(item); TodoListTableStorage storage = new TodoListTableStorage(); CloudTable table = storage.GetCloudTableReference(); await table.ExecuteAsync(operation); return(req.CreateResponse(HttpStatusCode.NoContent)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("CreateTodoList Invoked."); string body = await req.Content.ReadAsStringAsync(); ITodoList <IEnumerable <Item> > newList = JsonConvert.DeserializeObject <TodoList>(body); log.Info($"CreateTodoList Name: {newList.Name}."); // Define the row, string newItemGuid = Guid.NewGuid().ToString(); // Create the Entity and set the partition to signup, TodoListEntity listEntity = new TodoListEntity("todovue", newItemGuid); listEntity.Id = newItemGuid; listEntity.Name = newList.Name; listEntity.Items = JsonConvert.SerializeObject(new List <Item>()); TodoListTableStorage storage = new TodoListTableStorage(); CloudTable table = storage.GetCloudTableReference(); TableOperation insertOperation = TableOperation.Insert(listEntity); await table.ExecuteAsync(insertOperation); newList.Id = newItemGuid; return(req.CreateResponse(HttpStatusCode.OK, newList)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("GetAllTodoLists Invoked."); TodoListTableStorage storage = new TodoListTableStorage(); // Get All Lists TableQuery <TodoListEntity> query = new TableQuery <TodoListEntity>(); var results = storage.GetCloudTableReference().ExecuteQuery(query); List <ITodoList <IEnumerable <Item> > > items = new List <ITodoList <IEnumerable <Item> > >(); foreach (TodoListEntity todoListEntity in results) { TodoList resultItem = new TodoList(); resultItem.Id = todoListEntity.Id; resultItem.Name = todoListEntity.Name; resultItem.Items = JsonConvert.DeserializeObject <IEnumerable <Item> >(todoListEntity.Items); items.Add(resultItem); } var awaitedResult = await Task.FromResult(items); return(req.CreateResponse(HttpStatusCode.OK, awaitedResult)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "PUT", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("UpdateTodoList Invoked."); string body = await req.Content.ReadAsStringAsync(); ITodoList <IEnumerable <Item> > inputList = JsonConvert.DeserializeObject <TodoList>(body); log.Info($"UpdateTodoList Id: {inputList.Name}."); TodoListEntity updateEntity = new TodoListEntity("todovue", inputList.Id); updateEntity.Items = JsonConvert.SerializeObject(inputList.Items); updateEntity.Name = inputList.Name; updateEntity.Id = inputList.Id; updateEntity.ETag = "*"; //By default, the SDK enforces optimistic concurrency via ETags. Set this value to '*' in order to force an overwrite to an entity as part of an update operation. TableOperation operation = TableOperation.Replace(updateEntity); TodoListTableStorage storage = new TodoListTableStorage(); CloudTable table = storage.GetCloudTableReference(); await table.ExecuteAsync(operation); return(req.CreateResponse(HttpStatusCode.NoContent)); }