async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { Items.Clear(); var items = await ExpensesDataStore.GetItemsAsync(true); Items.ReplaceRange(items); } catch (Exception ex) { Debug.WriteLine(ex); MessagingCenter.Send(new MessagingCenterAlert { Title = "Error", Message = "Unable to load items.", Cancel = "OK" }, "message"); } finally { IsBusy = false; } }
public async Task AddAFile() { await FileService.AddFile((file) => { var expenseFiles = new ExpenseFile { ExpenseId = Item.ExpenseId, File = file.Bytes, Name = file.Name, Size = file.Size }; Item.ExpenseFiles.Add(expenseFiles); ExpensesDataStore.UpdateItemAsync(Item); ExpenseFiles.Add(expenseFiles); }); }
public ExpensesViewModel() { Title = "Browse"; Items = new ObservableRangeCollection <Expense>(); LoadItemsCommand = new Command(async() => await ExecuteLoadItemsCommand()); MessagingCenter.Subscribe <NewExpensePage, Expense>(this, "AddItem", async(obj, item) => { var _item = item as Expense; await ExpensesDataStore.AddItemAsync(_item); Items.Add(_item); }); }
public ExpenseDetailViewModel(Expense item = null) { Title = item.Name; Item = item; ExpenseFiles = new ObservableCollection <ExpenseFile>(); foreach (var expenseFile in Item.ExpenseFiles) { ExpenseFiles.Add(expenseFile); } SetLines(); MessagingCenter.Subscribe <PayForExpensePage, Expense>(this, "PayForExpense", async(obj, it) => { Item.PaidDate = it.PaidDate; Item.PaidValue = it.PaidValue; Item.Paid = true; await ExpensesDataStore.UpdateItemAsync(Item); SetLines(); }); }