public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case (Resource.Id.menu_save_expense): viewModel.Name = name.Text; viewModel.Billable = billable.Checked; viewModel.Due = date.DateTime; viewModel.Notes = notes.Text; viewModel.Total = total.Text; viewModel.Category = viewModel.Categories[category.SelectedItemPosition]; Task.Run(async() => { await viewModel.ExecuteSaveExpenseCommand(); if (!viewModel.CanNavigate) { return; } Finish(); }); return(true); } return(base.OnOptionsItemSelected(item)); }
public override void ViewDidLoad() { base.ViewDidLoad(); NavigationController.NavigationBar.BarStyle = UIBarStyle.Black; var title = expense == null ? "New Expense" : "Edit Expense"; this.Root = new RootElement(title) { new Section("Expense Details") { (name = new EntryElement("Name", "Expense Name", string.Empty)), (total = new EntryElement("Total", "1.00", string.Empty) { KeyboardType = UIKeyboardType.DecimalPad }), (billable = new CheckboxElement("Billable", true)), new RootElement("Category", categories = new RadioGroup("category", 0)) { new Section() { from category in viewModel.Categories select(Element) new RadioElement(category) } }, (due = new DateElement("Due Date", DateTime.Now)) }, new Section("Notes") { (notes = new EntryElement(string.Empty, "Enter expense notes.", string.Empty)) } }; billable.Value = viewModel.Billable; name.Value = viewModel.Name; total.Value = viewModel.Total; notes.Caption = viewModel.Notes; categories.Selected = viewModel.Categories.IndexOf(viewModel.Category); due.DateValue = viewModel.Due; this.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Save, async delegate { viewModel.Category = viewModel.Categories[categories.Selected]; viewModel.Name = name.Value; viewModel.Billable = billable.Value; viewModel.Due = due.DateValue; viewModel.Notes = notes.Caption; viewModel.Total = total.Value; await viewModel.ExecuteSaveExpenseCommand(); if (!viewModel.CanNavigate) { return; } NavigationController.PopToRootViewController(true); }); }
private async void SaveAppButton_OnClick(object sender, EventArgs e) { await viewModel.ExecuteSaveExpenseCommand(); if (!viewModel.CanNavigate) { return; } NavigationService.GoBack(); }