async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { Items.Clear(); ItemsGrouped.Clear(); var items = await DataStoreNew.GetItemsAsync <Invoice>(); foreach (var item in items) { Items.Add(item); } foreach (var group in items.GroupBy(x => x.SellerName)) { ItemsGrouped.Add(group); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public InvoiceListViewModel() { Title = "Invoices"; Items = new ObservableCollection <Invoice>(); ItemsGrouped = new ObservableCollection <IGrouping <string, Invoice> >(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); ReloadInvoicesFromServer = new Command(async() => await ExecuteReloadInvoicesFromServerCommand()); MessagingCenter.Subscribe <NewItemPage, Invoice>(this, "AddItem", async(obj, item) => { var _item = item as Invoice; Items.Add(_item); await DataStoreNew.AddItemAsync(_item); }); }