public BillingPageViewModel() { Title = "Billing Entries"; Items = new ObservableCollection <BillingEntry>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <NewBillingEntryPage, BillingEntry> (this, "AddEntry", async(obj, entry) => { var _entry = entry as BillingEntry; Items.Add(_entry); try { await AzureDataStore.DefaultStore.AddItemAsync(_entry); } catch { await LocalDataStore.AddItemAsync(_entry); } }); MessagingCenter.Subscribe <BillingEntryDetailPage, BillingEntry> (this, "UpdateEntry", async(obj, entry) => { var _entry = Items.Where((BillingEntry arg) => arg.Id == entry.Id).FirstOrDefault(); _entry.ClientName = entry.ClientName; _entry.BillingDate = entry.BillingDate; _entry.BillingTime = entry.BillingTime; _entry.Notes = entry.Notes; //Items.Add(_entry); try { await AzureDataStore.DefaultStore.UpdateItemAsync(_entry); } catch { await LocalDataStore.UpdateItemAsync(_entry); } }); MessagingCenter.Subscribe <BillingEntryDetailPage, BillingEntry> (this, "DeleteEntry", async(obj, entry) => { var _entry = Items.Where((BillingEntry arg) => arg.Id == entry.Id).FirstOrDefault(); Items.Remove(_entry); try { await AzureDataStore.DefaultStore.DeleteItemAsync(_entry.Id.ToString()); } catch { await LocalDataStore.DeleteItemAsync(_entry.Id.ToString()); } }); }
public ItemsViewModel() { Title = "Home"; accountManager = new AccountManager(); Items = new ObservableCollection <Item>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <ItemsPage, Item>(this, "RemoveItem", async(obj, item) => { bool result = await Application.Current.MainPage.DisplayAlert("Complete", "Have you completed this goal?", "No", "Yes"); if (result == false) { Items.Remove(item); await LocalDataStore.DeleteItemAsync(item.Id); } }); MessagingCenter.Subscribe <NewItemPage, Item>(this, "AddItem", async(obj, item) => { var _item = item as Item; // Encrypt _item.CipherText = GetCipherText(_item.Description); if (_item.CipherText != null) { Items.Add(_item); await LocalDataStore.AddItemAsync(_item); // Response code handling //await CloudDataStore.AddItemAsync(_item); } }); }