public void NewListItemKeyDown(KeyRoutedEventArgs args) { if (args.Key == VirtualKey.Enter) { if (!string.IsNullOrEmpty(NewListItemText)) { IsLoading = true; var index = GetListItemIndex(SelectedListModel, false, false); var newItem = new AvoListItem() { Text = NewListItemText, Id = "-1", ListId = SelectedListModel.Id }; SelectedListModel.Items.Insert(index, newItem); var clone = NewListItemText; var finalItem = newItem; var task = ThreadPool.RunAsync(t => { finalItem = AuthClient.CreateListItem(clone, SelectedListModel.Id, index); finalItem.ListId = newItem.ListId; }); task.Completed = RunOnComplete(() => { var i = SelectedListModel.Items.IndexOf(newItem); if (i >= 0) { SelectedListModel.Items[i] = finalItem; } IsLoading = false; }); } NewListItemText = ""; } }
public void EditListItem(AvoListItem listItem, bool delete = false, int index = -1) { if (string.IsNullOrEmpty(listItem.ListId)) { return; } IsLoading = true; var parentList = (from l in ListModelList where l.Id == listItem.ListId select l).First(); if (index == -1) { index = GetListItemIndex(parentList, listItem.Complete, listItem.Important); parentList.Items.Move(parentList.Items.IndexOf(listItem), index); SelectedListModel.Items = parentList.Items; } if (delete) { parentList.Items.Remove(listItem); } var task = ThreadPool.RunAsync(t => AuthClient.EditListItem(listItem, index, delete)); task.Completed = RunOnComplete(() => { IsLoading = false; }); }
public void ToggleListItemImportant(AvoListItem listItem) { listItem.Important = !listItem.Important; EditListItem(listItem); }
public void EditListItem(AvoListItem listItem, int index, bool delete = false) { if (listItem.Id == "-1") { return; } var uri = new Uri(API_URL_LISTS + listItem.ListId + "/" + listItem.Id + (delete ? "/delete" : "")); var body = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("text", listItem.Text), new KeyValuePair<string, string>("complete", listItem.Complete ? "1" : "0"), new KeyValuePair<string, string>("important", listItem.Important ? "1" : "0"), new KeyValuePair<string, string>("index", index.ToString()) }); if (delete) { body = new FormUrlEncodedContent(new KeyValuePair<string, string>[] { }); } var response = Post(uri, body); response.EnsureSuccessStatusCode(); }