public async Task TestInsertWithNoId() { var order = new Order { OrderDate = DateTime.UtcNow, Client = "John Doe", Items = new OrderItem[] { new OrderItem { Name = "Bread", Quantity = 1, Price = 1.99 } } }; await Table.InsertAsync(order); Assert.IsNotNull(order.Id); var inserted = await Table.LookupAsync(order.Id); Assert.AreEqual(order.OrderDate.ToUniversalTime(), inserted.OrderDate.ToUniversalTime()); Assert.AreEqual(order.Id, inserted.Id); Assert.AreEqual(order.Client, inserted.Client); CollectionAssert.AreEqual(order.Items, inserted.Items); // Cleanup await Table.DeleteAsync(order); }
internal override async System.Threading.Tasks.Task Send(IEnumerable <Task> tasks, IMobileServiceTable <Task> tasksTable, IEnumerable <TaskAssignedTo> taskAssignedToRelationship, IMobileServiceTable <TaskAssignedTo> taskAssignedToTable, Person user) { if (DeleteRelationshipOnly) { var list = await taskAssignedToTable.Where(p => p.TaskId == this.TaskId && p.PersonUserId == user.UserId).ToEnumerableAsync(); foreach (var taskAssignedTo in list) { await taskAssignedToTable.DeleteAsync(taskAssignedTo); } } else { var list = await taskAssignedToTable.Where(p => p.TaskId == this.TaskId).ToEnumerableAsync(); foreach (var taskAssignedTo in list) { await taskAssignedToTable.DeleteAsync(taskAssignedTo); } if (this.AzureTaskId != 0) { await tasksTable.DeleteAsync(new Task() { Id = AzureTaskId }); } } }
public async Task DeleteAsync() { string appUrl = "http://www.test.com"; string appKey = "secret..."; string collection = "tests"; var userDefinedParameters = new Dictionary <string, string>() { { "state", "WY" } }; TestServiceFilter hijack = new TestServiceFilter(); MobileServiceClient service = new MobileServiceClient(appUrl, appKey) .WithFilter(hijack); JsonObject obj = new JsonObject().Set("id", 12).Set("value", "new"); IMobileServiceTable table = service.GetTable(collection); await table.DeleteAsync(obj, userDefinedParameters); Assert.Contains(hijack.Request.Uri.ToString(), collection); Assert.IsNull(hijack.Request.Content); Assert.Contains(hijack.Request.Uri.Query, "state=WY"); ThrowsAsync <ArgumentNullException>(async() => await table.DeleteAsync(null)); ThrowsAsync <ArgumentException>(async() => await table.DeleteAsync(new JsonObject())); }
public async void DeleteTripItem(TripItem item) { if (item != null) { //delete all history IEnumerable <HistoryItem> historyItems = await historyTable.Where(i => i.TripId == item.Id).ToEnumerableAsync(); foreach (HistoryItem hitem in historyItems) { await historyTable.DeleteAsync(hitem); } //delete all payments IEnumerable <PaymentItem> paymentItems = await paymentTable.Where(i => i.TripId == item.Id).ToEnumerableAsync(); foreach (PaymentItem pitem in paymentItems) { IEnumerable <UserPaymentItem> userPayitem = await userpaymentTabel.Where(i => i.PayId == pitem.Id).ToEnumerableAsync(); foreach (UserPaymentItem uitem in userPayitem) { await userpaymentTabel.DeleteAsync(uitem); } await paymentTable.DeleteAsync(pitem); } await tripTable.DeleteAsync(item); } }
public async static Task DeleteFace(Face face) { faces = await faceTable.ToCollectionAsync(); JObject jo = new JObject(); jo.Add("id", face.Id); await faceTable.DeleteAsync(jo); }
public async void DeleteUserFromTripAsync(TripItem tripItem, string userId) { IEnumerable <TripUserItem> tripUserItems = await tripuserTable.Where(i => i.TripId == tripItem.Id && i.UserId == userId).ToEnumerableAsync(); foreach (TripUserItem item in tripUserItems) { await tripuserTable.DeleteAsync(item); } }
public async Task DeleteAsync_ThrowsPreconditionFailedException_WhenMergeConflictOccurs_Generic() { await EnsureEmptyTableAsync <ToDoWithSystemPropertiesType>(); string id = "an id"; IMobileServiceTable <ToDoWithSystemPropertiesType> table = GetClient().GetTable <ToDoWithSystemPropertiesType>(); // insert a new item var item = new ToDoWithSystemPropertiesType() { Id = id, String = "a value" }; await table.InsertAsync(item); Assert.IsNotNull(item.CreatedAt); Assert.IsNotNull(item.UpdatedAt); Assert.IsNotNull(item.Version); string version = item.Version; // Delete with wrong version item.Version = "abc"; item.String = "But wait!"; MobileServicePreconditionFailedException <ToDoWithSystemPropertiesType> expectedException = null; try { await table.DeleteAsync(item); } catch (MobileServicePreconditionFailedException <ToDoWithSystemPropertiesType> exception) { expectedException = exception; } Assert.IsNotNull(expectedException); Assert.AreEqual(expectedException.Response.StatusCode, HttpStatusCode.PreconditionFailed); string responseContent = await expectedException.Response.Content.ReadAsStringAsync(); JToken jtoken = responseContent.ParseToJToken(table.MobileServiceClient.SerializerSettings); string serverVersion = (string)jtoken["version"]; string stringValue = (string)jtoken["String"]; Assert.AreEqual(version, serverVersion); Assert.AreEqual(stringValue, "a value"); Assert.IsNotNull(expectedException.Item); Assert.AreEqual(version, expectedException.Item.Version); Assert.AreEqual(stringValue, expectedException.Item.String); // Delete one last time with the version from the server item.Version = serverVersion; await table.DeleteAsync(item); Assert.IsNull(item.Id); }
async void App_Suspending( Object sender, Windows.ApplicationModel.SuspendingEventArgs e) { // await new MessageDialog("Suspending").ShowAsync(); var onlineUser = new OnlineUsers { Id = "user_" + userUniqueID + "_id_" + randomID, username = String.Format("{0}", userUniqueID) }; await usersTable.DeleteAsync(onlineUser); }
private async void testupdate() { user u = new user { Id = 2 }; await todoTable.DeleteAsync(u); }
public async Task AsyncFilterSelectOrderingOperationsNotImpactedBySystemProperties() { await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>(); IMobileServiceTable <RoundTripTableItemWithSystemPropertiesType> table = GetClient().GetTable <RoundTripTableItemWithSystemPropertiesType>(); List <RoundTripTableItemWithSystemPropertiesType> items = new List <RoundTripTableItemWithSystemPropertiesType>(); // Insert some items for (int id = 0; id < 5; id++) { RoundTripTableItemWithSystemPropertiesType item = new RoundTripTableItemWithSystemPropertiesType() { Id = id.ToString(), Name = "a value" }; await table.InsertAsync(item); Assert.NotNull(item.CreatedAt); Assert.NotNull(item.UpdatedAt); Assert.NotNull(item.Version); items.Add(item); } // Selection var selectionResults = await table.Select(t => new { Id = t.Id, CreatedAt = t.CreatedAt }).ToEnumerableAsync(); var selectedItems = selectionResults.ToArray(); for (int i = 0; i < selectedItems.Length; i++) { var item = items.Where(t => t.Id == selectedItems[i].Id).FirstOrDefault(); Assert.Equal(item.CreatedAt, selectedItems[i].CreatedAt); } var selectionResults2 = await table.Select(t => new { Id = t.Id, UpdatedAt = t.UpdatedAt }).ToEnumerableAsync(); var selectedItems2 = selectionResults2.ToArray(); for (int i = 0; i < selectedItems2.Length; i++) { var item = items.Where(t => t.Id == selectedItems2[i].Id).FirstOrDefault(); Assert.Equal(item.UpdatedAt, selectedItems2[i].UpdatedAt); } var selectionResults3 = await table.Select(t => new { Id = t.Id, Version = t.Version }).ToEnumerableAsync(); var selectedItems3 = selectionResults3.ToArray(); for (int i = 0; i < selectedItems3.Length; i++) { var item = items.Where(t => t.Id == selectedItems3[i].Id).FirstOrDefault(); Assert.Equal(item.Version, selectedItems3[i].Version); } // Delete foreach (var item in items) { await table.DeleteAsync(item); } }
private async void Deny_Click(object sender, RoutedEventArgs e) { Button me = (Button)sender; String id = me.Content.ToString(); IMobileServiceTable <Credit> creditTable = App.MobileService.GetTable <Credit>(); MobileServiceCollection <Credit, Credit> creditRecords; p.IsActive = true; creditRecords = await creditTable.ToCollectionAsync <Credit>(); p.IsActive = false; IList <Credit> req = new List <Credit>(); ///Got the data foreach (var creditRecord in creditRecords) { p.IsActive = true; if ((creditRecord.Id).Equals(id, StringComparison.OrdinalIgnoreCase)) { creditRecord.Valid = false; await creditTable.DeleteAsync(creditRecord); break; } } p.IsActive = false; Frame.Navigate(typeof(favouritesPage)); }
public async Task DeletePreferito(Preferiti preferito) { await Initialize(); var preferiti = await preferitiTable.Where(x => x.UserId == Settings.UserId && x.IdCorso == preferito.IdCorso).ToEnumerableAsync(); if (preferiti.Count() > 0) { try { await preferitiTable.DeleteAsync(preferiti.FirstOrDefault()); } catch(Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } //TO DO try to delete Corso //devo verificare se ci sono altri utenti che hanno quel corso tra i preferiti, altrimenti lo "potrei" cancellare //if preferitiTable.Where(x => x.IdCorso == preferito.IdCorso).ToEnumerableAsync().Count() == 0) //allora cancello anche dalla tabella corso }
public async Task RefreshAsyncWithNoSuchItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); await table.DeleteAsync(item); item.Id = testId; await Assert.ThrowsAsync <InvalidOperationException>(() => table.RefreshAsync(item)); } }
// Removes a specific VoiceNote from the Azure database. When the Azure Mobile Service // responds, the item is removed from the local list private async void DeleteNoteAsync(VoiceNote note) { //Verify network connectivity is available before attempting to add note to database if (!NetworkInterface.GetIsNetworkAvailable()) { MessageBox.Show("Network connection unavailable. Please close app, verify your network connection, and try again."); return; } bool deleted = true; try { await noteTable.DeleteAsync(note); } catch (MobileServiceInvalidOperationException) { deleted = false; } if (deleted) { notes.Remove(note); } else { MessageBox.Show("Error with deletion. The selected note(s) have not been removed from the server."); } }
public async Task DeleteAsyncWithNosuchItemAgainstStringIdTable() { await EnsureEmptyTableAsync <ToDoWithStringId>(); string[] testIdData = IdTestData.ValidStringIds; IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); foreach (string testId in testIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = testId, Name = "Hey" }; await table.InsertAsync(item); } foreach (string testId in testIdData) { ToDoWithStringId item = await table.LookupAsync(testId); await table.DeleteAsync(item); item.Id = testId; var exception = await Assert.ThrowsAnyAsync <MobileServiceInvalidOperationException>(() => table.DeleteAsync(item)); Assert.Equal(HttpStatusCode.NotFound, exception.Response.StatusCode); Assert.True(exception.Message == "The item does not exist" || exception.Message == "The request could not be completed. (Not Found)"); } }
private async Task deleteWeighs(DateTime time) { MobileServiceClient client = ToDoActivity.CurrentActivity.CurrentClient; try { weighTableRef = client.GetTable <weighTable>(); //get all the to be deleted weights - the weights before the specified date var toBeDeleted = await weighTableRef.Where(item => (item.username == ourUserId) && (item.createdAt <= time)).ToListAsync(); if (toBeDeleted.Count == 0) { //CreateAndShowDialog("No weights were found prior to the specified date", "Cannot Delete"); FindViewById <TextView>(Resource.Id.date_display).Text = "Cannot Delete.\nNo weights were found prior to the specified date"; } else { foreach (weighTable weight in toBeDeleted) { await weighTableRef.DeleteAsync(weight); //Console.WriteLine("SLEEPING !!!!!!!!!!!!!!!!!!!"); //await Task.Delay(90000); //object o2 = null; //int i2 = (int)o2; } FindViewById <TextView>(Resource.Id.date_display).Text = "Deleted Successfully"; } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
public async void SendMessage() { MobileServiceInvalidOperationException exception = null; try { // This code refreshes the entries in the list view by querying the TodoItems table. // The query excludes completed TodoItems items = await todoTable.ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { exception = e; } if (exception != null) { Log.Debug("Helper", exception.Message); //await new MessageDialog(exception.Message, "Error loading items").ShowAsync(); //dont know on andorid } else { foreach (TodoItem T in this.items) { Console.WriteLine(T.phoneno, T.messageval); SmsManager.Default.SendTextMessage(T.phoneno, null, T.messageval, null, null); Log.Debug("Message Sent: ", T.phoneno); await todoTable.DeleteAsync(T); Log.Debug("Message Deleted: ", T.phoneno + " - " + T.id); } } }
private async void Button_Eliminar_Clicked(object sender, EventArgs e) { if (txtNombre.Text == null || txtDescripcion.Text == null || txtPrecio.Text == null || txtImagen.Text == null) { await DisplayAlert("Error", "Es obligatorio llenar todos los campos", "OK"); } else { var datos = new productos { Id = txtID.Text, Nombre = txtNombre.Text, Descripcion = txtDescripcion.Text, Precio = txtPrecio.Text, Imagen = txtImagen.Text }; try { await Tabla.DeleteAsync(datos); await DisplayAlert("Eliminado", "Tarea Eliminada correctamente", "OK"); } catch (Exception error) { await DisplayAlert("error", "" + error, "OK"); } } }
public async void EasyTablesTest() { ClearOutput(); WriteLine("-- Testing Easy Tables --"); WriteLine("Getting table"); IMobileServiceTable <TodoItem> tbl = Client.GetTable <TodoItem>(); WriteLine("Inserting new item"); try { await tbl.InsertAsync(new TodoItem { Text = "New item" }); WriteLine("Getting unfinished items"); List <TodoItem> list = await tbl.Where(i => i.Complete == false).ToListAsync(); foreach (TodoItem item in list) { WriteLine($"{item.Id} - {item.Text} - {item.Complete}"); } WriteLine("Updating first item"); list[0].Complete = true; await tbl.UpdateAsync(list[0]); WriteLine("Deleting first item"); await tbl.DeleteAsync(list[0]); } catch (Exception e) { WriteLine(e.ToString()); } WriteLine("-- Test Complete --"); }
public async Task AsyncFilterSelectOrdering_FilterByCreatedAt_NotImpactedBySystemProperties() { // Set up the table. await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>(); IMobileServiceTable <RoundTripTableItemWithSystemPropertiesType> table = GetClient().GetTable <RoundTripTableItemWithSystemPropertiesType>(); List <RoundTripTableItemWithSystemPropertiesType> items = new List <RoundTripTableItemWithSystemPropertiesType>(); for (int id = 0; id < 5; id++) { RoundTripTableItemWithSystemPropertiesType item = new RoundTripTableItemWithSystemPropertiesType() { Id = id.ToString(), Name = "a value" }; await table.InsertAsync(item); Assert.NotNull(item.CreatedAt); Assert.NotNull(item.UpdatedAt); Assert.NotNull(item.Version); items.Add(item); } // Run test var results = await table.Where(t => t.CreatedAt >= items[4].CreatedAt).ToListAsync(); RoundTripTableItemWithSystemPropertiesType[] filteredItems = results.ToArray(); for (int i = 0; i < filteredItems.Length - 1; i++) { Assert.True(filteredItems[i].CreatedAt >= items[4].CreatedAt); } // Cleanup items.ForEach(async t => await table.DeleteAsync(t)); }
public MainPage() { InitializeComponent(); this.client = new MobileServiceClient("http://doggylab.azurewebsites.net"); this.todoTable = client.GetTable <DoggyTodo>(); todoList.Refreshing += TodoList_Refreshing; buttonAdd.Clicked += async(s, e) => { await todoTable.InsertAsync(new DoggyTodo { Name = DateTime.Now.ToString() }); await Refresh(); }; buttonDel.Clicked += async(s, e) => { if (todoList.SelectedItem != null) { var fooItem = (DoggyTodo)todoList.SelectedItem; await todoTable.DeleteAsync(fooItem); await Refresh(); } }; }
public async Task FilterReadAsyncWithIntegerAsStringIdAgainstIntegerIdTable() { await EnsureEmptyTableAsync <ToDoWithIntId>(); IMobileServiceTable <ToDoWithIntId> table = GetClient().GetTable <ToDoWithIntId>(); List <ToDoWithIntId> integerIdItems = new List <ToDoWithIntId>(); for (var i = 0; i < 10; i++) { ToDoWithIntId item = new ToDoWithIntId() { String = i.ToString() }; await table.InsertAsync(item); integerIdItems.Add(item); } IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>(); IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.Where(p => p.Id == integerIdItems[0].Id.ToString()).ToEnumerableAsync(); ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray(); Assert.AreEqual(1, items.Count()); Assert.AreEqual(integerIdItems[0].Id.ToString(), items[0].Id); Assert.AreEqual("0", items[0].String); foreach (ToDoWithIntId integerIdItem in integerIdItems) { await table.DeleteAsync(integerIdItem); } }
//private IMobileServiceSyncTable<TodoItem> todoTable = App.MobileService.GetSyncTable<TodoItem>(); // offline sync public async Task DeleteTodoItem(TodoItem todoItem) { // This code deletes a TodoItem from the database. await todoTable.DeleteAsync(todoItem); //await SyncAsync(); // offline sync }
public async Task DeleteAsync_ThrowsPreconditionFailedException_WhenMergeConflictOccurs() { await EnsureEmptyTableAsync <ToDoWithSystemPropertiesType>(); string id = "an id"; IMobileServiceTable table = GetClient().GetTable("stringId_test_table"); var item = new JObject() { { "id", id }, { "String", "a value" } }; var inserted = await table.InsertAsync(item); item["version"] = "random"; MobileServicePreconditionFailedException expectedException = null; try { await table.DeleteAsync(item); } catch (MobileServicePreconditionFailedException ex) { expectedException = ex; } Assert.IsNotNull(expectedException); Assert.AreEqual(expectedException.Value["version"], inserted["version"]); Assert.AreEqual(expectedException.Value["String"], inserted["String"]); }
public async Task DeleteAsync_ThrowsPreconditionFailedException_WhenMergeConflictOccurs() { await EnsureEmptyTableAsync <RoundTripTableItemWithSystemPropertiesType>(); string id = Guid.NewGuid().ToString(); IMobileServiceTable table = GetClient().GetTable("RoundTripTable"); var item = new JObject() { { "id", id }, { "name", "a value" } }; var inserted = await table.InsertAsync(item); item["version"] = "3q3A3g=="; MobileServicePreconditionFailedException expectedException = null; try { await table.DeleteAsync(item); } catch (MobileServicePreconditionFailedException ex) { expectedException = ex; } Assert.IsNotNull(expectedException); Assert.AreEqual(expectedException.Value["version"], inserted["version"]); Assert.AreEqual(expectedException.Value["name"], inserted["name"]); }
public async Task InsertAsyncWithEmptyStringIdAgainstStringIdTable() { string[] emptyIdData = IdTestData.EmptyStringIds.Concat( new string[] { null }).ToArray(); IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>(); int count = 0; List <ToDoWithStringId> itemsToDelete = new List <ToDoWithStringId>(); foreach (string emptyId in emptyIdData) { ToDoWithStringId item = new ToDoWithStringId() { Id = emptyId, String = (++count).ToString() }; await table.InsertAsync(item); Assert.IsNotNull(item.Id); Assert.AreEqual(count.ToString(), item.String); itemsToDelete.Add(item); } foreach (var item in itemsToDelete) { await table.DeleteAsync(item); } }
public async void Delete(EventInvites item) { // This code takes a freshly completed Events and updates the database. When the MobileService // responds, the item is removed from the list await mobileServiceTable.DeleteAsync(item); //items.Remove(item); }
/*public async Task SyncAsync() * { * ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null; * * try * { * await this.client.SyncContext.PushAsync(); * await this.NetWorkTable.PullAsync("nt1", this.NetWorkTable.CreateQuery().Where(item=>item.FPID==prof.ID)); * foreach (var x in await NetWorkTable.ToListAsync()) * { * await this.profileTable.PullAsync("p2", this.profileTable.CreateQuery().Where(item=> item.ID==x.SPID)); * * * } * * await this.NotesIDTable.PullAsync("ni1", this.NotesIDTable.CreateQuery().Where(item=>item.NTID==prof.ID) ); * foreach(var x in await NotesIDTable.ToListAsync()) * { * await this.NoteTable.PullAsync("n1", this.NoteTable.CreateQuery().Where(item => item.NID ==x.NTID)); * * } * //await this.NoteTable.PullAsync("n1", this.NoteTable.CreateQuery().Where(item=> item.NID==)); * * * } * catch (MobileServicePushFailedException exc) * { * if (exc.PushResult != null) * { * syncErrors = exc.PushResult.Errors; * } * } * * * if (syncErrors != null) * { * foreach (var error in syncErrors) * { * if (error.OperationKind == MobileServiceTableOperationKind.Update && error.Result != null) * { * //Update failed, reverting to server's copy. * await error.CancelAndUpdateItemAsync(error.Result); * } * else * { * // Discard local change. * await error.CancelAndDiscardItemAsync(); * } * * * } * } * }*/ public async Task DeleteNetWorkAsync(Profile item) { List <NetWork> z = await NetWorkTable.Where(items => items.FPID == prof.ID && items.SPID == item.ID).ToListAsync();//değiştirilmiş girdi z.First().Deleted = true; NetWorkTable.DeleteAsync(z.First()); }
private async void UpdateCheckedTodoItem(TodoItem item) { // This code takes a freshly completed TodoItem and updates the database. When the MobileService // responds, the item is removed from the list await todoTable.DeleteAsync(item); // items.Remove(item); }
public async Task DeleteCorso (Corso corso) { await Initialize(); var c = await GetCorso(corso); if(c != null) await corsoTable.DeleteAsync(c); }
internal override async System.Threading.Tasks.Task Send(IEnumerable<Task> tasks, IMobileServiceTable<Task> tasksTable, IEnumerable<TaskAssignedTo> taskAssignedToRelationship, IMobileServiceTable<TaskAssignedTo> taskAssignedToTable, Person user) { if (DeleteRelationshipOnly) { var list = await taskAssignedToTable.Where(p => p.TaskId == this.TaskId && p.PersonUserId == user.UserId).ToEnumerableAsync(); foreach (var taskAssignedTo in list) await taskAssignedToTable.DeleteAsync(taskAssignedTo); } else { var list = await taskAssignedToTable.Where(p => p.TaskId == this.TaskId).ToEnumerableAsync(); foreach (var taskAssignedTo in list) await taskAssignedToTable.DeleteAsync(taskAssignedTo); if (this.AzureTaskId != 0) { await tasksTable.DeleteAsync(new Task() { Id = AzureTaskId }); } } }
private async void CheckNetworkAvailability() { online = NetworkInterface.NetworkInterfaceType.ToString()!="None"; if (online) { MobileService = new MobileServiceClient( "https://shopappdata.azure-mobile.net/", "dkwwuiuHYYQwbozjKaWRJYYpEiTjFt73" ); itemTable = MobileService.GetTable<Items>(); buffer = XmlTaskService.GetTasks("buffer.xml"); foreach (Items buffitem in buffer) { try { await itemTable.InsertAsync(buffitem); XmlTaskService.CreateTask(buffitem, "tasks.xml"); } catch { } } XmlTaskService.DeleteAllTasks("buffer.xml"); buffer.Clear(); buffer = XmlTaskService.GetTasks("checked.xml"); foreach (Items buffitem in buffer) { Debug.WriteLine("Item is "); Debug.WriteLine(buffitem.Text) ; checked_item = XmlTaskService.GetTasksByText(buffitem.Text, "tasks.xml"); checked_item.shared = true; Debug.WriteLine("checked"); Debug.WriteLine(checked_item.Text); try { await itemTable.UpdateAsync(checked_item); } catch { } } XmlTaskService.DeleteAllTasks("checked.xml"); buffer.Clear(); buffer = XmlTaskService.GetTasks("delete.xml"); foreach (Items buffitem in buffer) { checked_item = XmlTaskService.GetTasksByText(buffitem.Text, "tasks.xml"); try { await itemTable.DeleteAsync(checked_item); } catch { } } XmlTaskService.DeleteAllTasks("delete.xml"); buffer.Clear(); } }
// Function to buy item private async void BuyItem(object sender, System.Windows.Input.GestureEventArgs e) { if (online) { var itemId = ((Button)sender).Tag.ToString(); string itemName = null; foreach (var objects in ((Grid)((Button)sender).Parent).Children) { if (objects is TextBlock) { itemName = ((TextBlock)objects).Text; } } // Remove item corresponding to itemId/itemName from database. XmlTaskService.DeleteTask(itemName, "tasks.xml"); // Remove item corresponding to itemId/itemName from XML tables. itemTable = MobileService.GetTable<Items>(); var parent = (ListBox)((Grid)((Button)sender).Parent).Parent; parent.Items.Remove(((Grid)((Button)sender).Parent)); try { var myList1 = await itemTable.Where(itemabc => itemabc.Id.ToString() == itemId).ToListAsync(); await itemTable.DeleteAsync(myList1[0]); var uid = myList1[0].User_Id; var todoItem = new Notify { Message = user_name + " has bought " + itemName + " for you", Type = "", User_Id = uid }; var notifyTable = MobileService.GetTable<Notify>(); await notifyTable.InsertAsync(todoItem); } catch { return; } } }