public async Task SaveAccountAsync(Account item) { try { using (var handle = Insights.TrackTime("TimeToSaveAccount")) { if (item.Id == null) { await _AccountTable.InsertAsync(item); } else { await _AccountTable.UpdateAsync(item); } } } catch (MobileServiceInvalidOperationException ex) { Insights.Report(ex, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex.Message); } catch (Exception ex2) { Insights.Report(ex2, Insights.Severity.Error); Debug.WriteLine(@"ERROR {0}", ex2.Message); } }
public async Task <T> SaveItemAsync(T item) { try { if (item.Id != null) { await table.UpdateAsync(item); } else { try { await table.InsertAsync(item); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch (Exception ex) { Debug.WriteLine($"Error: {ex.Message}"); } return(item); }
public async Task SaveAsync(T item) { try { if (item.Id == null) { if (isSyncTable) { await syncTable.InsertAsync(item); } else { await dataTable.InsertAsync(item); } dataView.Add(item); } else { if (isSyncTable) { await syncTable.UpdateAsync(item); } else { await dataTable.UpdateAsync(item); } dataView.Remove(item); dataView.Add(item); } } catch (MobileServiceInvalidOperationException exception) { throw new CloudTableOperationFailed(exception.Message, exception); } }
public async Task <Models.Product> SaveProductAsync(Models.Product item) { try { if (item.Id == null) { if ((await this.productTable.ToEnumerableAsync()).Any()) { int lastProductNumber = (await this.productTable.Select(c => int.Parse(c.ProductNumber.TrimStart('P'))).ToListAsync()).Max(); item.ProductNumber = $"P{lastProductNumber + 1}"; } else { item.ProductNumber = "P0001"; } await productTable.InsertAsync(item); } else { await productTable.UpdateAsync(item); } } catch (Exception e) { Debug.WriteLine("Save error: {0}", new[] { e.Message }); return(null); } this.messenger.Publish <ProductUpdatedMessage>(new ProductUpdatedMessage(this, item)); return(item); }
public async Task CheckItem(ToDoItem item) { if (client == null) { return; } // Set the item as completed and update it in the table item.Complete = true; try { // Update the new item in the local store. await todoTable.UpdateAsync(item); #if OFFLINE_SYNC_ENABLED // Send changes to the mobile app backend. await SyncAsync(); #endif if (item.Complete) { adapter.Remove(item); } } catch (Exception e) { CreateAndShowDialog(e, "Error"); } }
/// <summary> /// Task for pushing receivied and parsed meters into the local sqlite database. /// </summary> /// <returns></returns> private async Task SyncReadQueue() { JsonMeterModel MeterToSync; while (IsR2Initialized && IsR2Listening) { SyncStatus = MeterSyncQueue.Count + " Meters in Update Queue"; if (MeterSyncQueue.Any()) { try { MeterToSync = MeterSyncQueue.Dequeue(); if (Meters.Where(meter => meter.MeterInfo.MeterId == MeterToSync.MeterId).Any()) { await RouteSyncTable.UpdateAsync(MeterToSync); } else { await RouteSyncTable.InsertAsync(MeterToSync); } } catch (Exception ex) { SyncStatus = ex.Message; } } } }
public async Task UpdateTodoItem(TodoItem todoItem) { if (todoItem.ImageUploadPending) { // Set blob properties of TodoItem. todoItem.ContainerName = "todoitemimages"; // Use a unigue GUID to avoid collisions. todoItem.ResourceName = Guid.NewGuid().ToString(); } // This code updates a TodoItem in the local database. await todoTable.UpdateAsync(todoItem); await SyncWithImagesAsync(); // offline sync }
public async Task UpdateSightFileAsync(SightFile sightFile) { try { await InitializeAsync(); // Get unaltered one var sightFileOriginal = await sightFileTable.LookupAsync(sightFile.Id.ToString()); await sightFileTable.UpdateAsync(sightFile); if (sightFileOriginal?.Uri != sightFile.Uri) { // Image file has changed - upload the new file if (sightFile.Uri?.StartsWith("ms-appdata") ?? false) { // So we only care about files with ms-appdata uri which have been created by the user - these we sync to the cloud sightFile.File = await sightFileTable.AddFileAsync(sightFile, sightFile.FileName); } } await SyncAsync(); // offline sync } catch (Exception ex) { var errorString = "Update SightFile failed: " + ex.Message + "\n\nIf you are still in an offline scenario, " + "you can try your Pull again when connected with your Mobile Service."; await ShowError(errorString); throw; } }
public async Task UpdateNote(Notes notes) { // var table = _mobileServiceClient.GetTable<Notes>(); await SyncNotes(); await _notesTable.UpdateAsync(notes); }
public async Task AddUpdateItemAsync(FocaccePost focaccePost) { try { IMobileServiceSyncTable <FocaccePost> Focacciatable = client.GetSyncTable <FocaccePost>(); if (string.IsNullOrEmpty(focaccePost.Id)) { //e' un inserimento await Focacciatable.InsertAsync(focaccePost); } else { //è una modifica await Focacciatable.UpdateAsync(focaccePost); } //await PushModifiche(); } catch (Exception e) { throw; } }
public async void BuyProducts(string Pname) { string productname = Pname; await Initialize(); await SyncBookings(); try { List <Shop_Two> item = await shopz .Where(todoItem => todoItem.ProductName == productname) .ToListAsync(); foreach (var x in item) { x.Quantity = 8; await shopz.UpdateAsync(x); await SyncBookings(); await DisplayAlert("Alert", "Done", "Ok"); } } catch (Exception er) { await DisplayAlert("Alert", "Error: " + er, "Ok"); } }
private async Task ProcessSync() { ReadOnlyCollection <MobileServiceTableOperationError> syncErrors = null; try { await _table.Where(t => t.IsLocal).ToListAsync().ContinueWith(async (b) => { foreach (Contact c in b.Result) { c.IsLocal = false; await _table.UpdateAsync(c); } }); await _client.SyncContext.PushAsync() .ContinueWith((b) => { SetNotification(GetPendingOperations()); }); await _table.PullAsync("allContacts", _table.CreateQuery()); } catch (MobileServicePushFailedException pushEx) { if (pushEx.PushResult != null) { syncErrors = pushEx.PushResult.Errors; } } }
public async Task UpdateJobAsync(Job job) { job.Status = Job.CompleteStatus; // 5. update local db await jobTable.UpdateAsync(job); }
/***************************************************************** * METHOD TO uPDATE THE A PERSON ****************************************************************/ public async Task <Person> UpdatePersons(Person editSelection) { await Intialize(); // await SyncProducts(); string answer = "false"; //System.Diagnostics.Debug.WriteLine((await App.MobileService.GetTable<User>().LookupAsync(1) as User).firstName); //User item = await coffeeTable.LookupAsync("6cc1aca348714a26af9c1d9d1757d0c2"); var Prod = await personTable .Where(p => p.Id == editSelection.Id) .ToListAsync(); //Then change the properties you want and after that call UpdateAsync var editPerson = new Person { Id = editSelection.Id, FirstName = editSelection.FirstName, LastName = editSelection.LastName, Age = editSelection.Age, PPSN = editSelection.PPSN, CardNumber = editSelection.CardNumber }; // var inserted = await productTable.UpdateAsync(jo); // editSelection.ProductName = //Debug.WriteLine("the error: " + editSelection.Id.ToString()); await personTable.UpdateAsync(editPerson); await SyncPersons(); return(editSelection); }
public async Task <bool> SaveUserAsync(User _user) { // if the email field is null, create a new user in azure await Initialize(); try { if (_user.email == null) { await UserTable.InsertAsync(_user); } // else, the user is updating their preferred default location else { await UserTable.UpdateAsync(_user); } await SyncUserAsync(); return(true); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return(false); } }
private async void BtnAgregarClick(object sender, EventArgs e) { try { EditText nombre = FindViewById <EditText>(Resource.Id.editText1); EditText descripcion = FindViewById <EditText>(Resource.Id.editText2); EditText inventario = FindViewById <EditText>(Resource.Id.editText3); EditText precio = FindViewById <EditText>(Resource.Id.editText4); if (string.IsNullOrWhiteSpace(idProducto)) { await torneoItemTable.InsertAsync(new Productos { Nombre = nombre.Text, Descripcion = descripcion.Text, Inventario = Convert.ToDecimal(inventario.Text), Precio = Convert.ToDecimal(precio.Text) }); } else { await torneoItemTable.UpdateAsync(new Productos { Id = idProducto, Nombre = nombre.Text, Descripcion = descripcion.Text, Inventario = Convert.ToDecimal(inventario.Text), Precio = Convert.ToDecimal(precio.Text) }); } } catch (Exception ex) { CreateAndShowDialog(ex, "Error al guardar"); } }
public async Task <Models.Vendor> SaveVendorAsync(Models.Vendor item) { try { if (item.Id == null) { if ((await this.vendorTable.ToEnumerableAsync()).Any()) { int lastVendorNumber = (await this.vendorTable.Select(c => int.Parse(c.VendorNumber.TrimStart('V'))).ToListAsync()).Max(); item.VendorNumber = $"V{lastVendorNumber + 1}"; } else { item.VendorNumber = "V000001"; } await vendorTable.InsertAsync(item); } else { await vendorTable.UpdateAsync(item); } } catch (Exception e) { Debug.WriteLine("Save error: {0}", new[] { e.Message }); return(null); } this.messenger.Publish <VendorUpdatedMessage>(new VendorUpdatedMessage(this, item)); return(item); }
public async Task SystemPropertiesArePreserved_OnlyWhenReturnedFromServer() { ResetDatabase(TestTable); var hijack = new TestHttpHandler(); var store = new MobileServiceSQLiteStore(TestDbName); store.DefineTable <ToDoWithSystemPropertiesType>(); IMobileServiceClient service = await CreateClient(hijack, store); IMobileServiceSyncTable <ToDoWithSystemPropertiesType> table = service.GetSyncTable <ToDoWithSystemPropertiesType>(); // first insert an item var updatedItem = new ToDoWithSystemPropertiesType() { Id = "b", String = "Hey", Version = "abc", CreatedAt = new DateTime(2013, 1, 1, 1, 1, 1, DateTimeKind.Utc), UpdatedAt = new DateTime(2013, 1, 1, 1, 1, 2, DateTimeKind.Utc) }; await table.UpdateAsync(updatedItem); var lookedupItem = await table.LookupAsync("b"); Assert.Equal("Hey", lookedupItem.String); Assert.Equal("abc", lookedupItem.Version); // we ignored the sys properties on the local object Assert.Equal(lookedupItem.CreatedAt, new DateTime(0, DateTimeKind.Utc)); Assert.Equal(lookedupItem.UpdatedAt, new DateTime(0, DateTimeKind.Utc)); Assert.Equal(1L, service.SyncContext.PendingOperations); // operation pending hijack.OnSendingRequest = async req => { string content = await req.Content.ReadAsStringAsync(); Assert.Equal(@"{""id"":""b"",""String"":""Hey""}", content); // the system properties are not sent to server return(req); }; string updateResult = "{\"id\":\"b\",\"String\":\"Wow\",\"version\":\"def\",\"createdAt\":\"2014-01-29T23:01:33.444Z\", \"updatedAt\":\"2014-01-30T23:01:33.444Z\"}"; hijack.Responses.Add(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(updateResult) }); // push await service.SyncContext.PushAsync(); Assert.Equal(0L, service.SyncContext.PendingOperations); // operation removed lookedupItem = await table.LookupAsync("b"); Assert.Equal("Wow", lookedupItem.String); Assert.Equal("def", lookedupItem.Version); // we preserved the system properties returned from server on update Assert.Equal(lookedupItem.CreatedAt.ToUniversalTime(), new DateTime(2014, 01, 29, 23, 1, 33, 444, DateTimeKind.Utc)); Assert.Equal(lookedupItem.UpdatedAt.ToUniversalTime(), new DateTime(2014, 01, 30, 23, 1, 33, 444, DateTimeKind.Utc)); }
public async Task ActualizaListado(Listado persona) { await Initialize(); await table.UpdateAsync(persona); await SyncListado(); }
public async Task<bool> UpdateItemAsync(Item item) { await InitializeAsync(); await itemsTable.UpdateAsync(item); await SyncAsync(); return true; }
public async Task <bool> UpdateItemAsync(T item) { await itemsTable.UpdateAsync(item); await SyncAsync(); return(true); }
public async Task UpdateTransaction(Transactions trans) { await Initialize(); await transactionTable.UpdateAsync(trans); await SyncTransaction(); }
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.UpdateAsync(item); items.Remove(item); }
public async Task UpdateToDo(ToDoItem item) { await this.Initializer(); //var table = client.GetSyncTable<ToDoItem>(); await table.UpdateAsync(item); }
public async Task UpdateMessage(ChatMessage message) { await Initialize(); await messageTable.UpdateAsync(message); await SyncMessage(); }
public async Task UpdateSpeaker(Speaker speaker) { await Initialize(); await table.UpdateAsync(speaker); await SyncSpeakers(); }
public async void NotGuncelle(Notlar not) { //await App.mobilServis.GetTable<Notlar>().UpdateAsync(not); //return await veritabani.UpdateAsync(not); await notlarTablosu.UpdateAsync(not); //await App.mobilServis.SyncContext.PushAsync(); await ZamanUyumsuzSenkronizasyon(); }
public async Task UpdateJobAsync(Job job) { job.Status = Job.CompleteStatus; await jobTable.UpdateAsync(job); // trigger an event so that the job list is refreshed await MobileService.EventManager.PublishAsync(new MobileServiceEvent("JobChanged")); }
public async Task UpdateData(string id, string period, string periodId, string timesheetLines, string timesheetWork) { var offline = new OfflineTimesheetModel { period = period, offlineTimesheetLines = timesheetLines, offlineTimesheetWork = timesheetWork }; await offlineTimesheet.UpdateAsync(offline); await SyncData(true); }
public async Task CompleteItemAsync(LotData item) { try { await lotDataTable.UpdateAsync(item); // update todo item in the local database await SyncAsync(); // send changes to the mobile service } catch (MobileServiceInvalidOperationException e) { Console.Error.WriteLine(@"ERROR {0}", e.Message); } }