public MainPage() { InitializeComponent(); var goalDatabase = new GoalDatabase(); BindingContext = new MainPageViewModel(goalDatabase, new NavigationService(Navigation)); }
public MyGoalViewModel(ISqlite sqlite, IDialogService dialog) { this.dialog = dialog; SelectedGoals = new ObservableCollection <SelectedGoal>() { }; this.selectedGoalDatabase = new SelectedGoalDatabase(sqlite); this.goalDatabase = new GoalDatabase(sqlite); loadSelectedGoalsFromDbToday(); ViewSelectedGoalCommand = new MvxCommand <SelectedGoal>(selectedSelectedGoal => { ShowViewModel <GoalUpdateViewModel>(new { selectedGoalId = selectedSelectedGoal.Id }); } ); }
public GoalListViewModel(ISqlite sqlite, IDialogService dialog) { this.dialog = dialog; Goals = new ObservableCollection <Goal>() { }; this.goalDatabase = new GoalDatabase(sqlite); this.selectedGoalDatabase = new SelectedGoalDatabase(sqlite); // only do this for one time, it will clear existing database. beware, may clear dependencies insertSampleGoalsToDbIfNotExist(); loadGoalsFromDb(); SelectGoalCommand = new MvxCommand <Goal>(selectedGoal => { ShowViewModel <GoalDetailViewModel>(selectedGoal); } ); }
public GoalDiaryViewModel(ISqlite sqlite, IDialogService dialog) { this.dialog = dialog; SelectedGoals = new ObservableCollection <SelectedGoal>() { }; this.selectedGoalDatabase = new SelectedGoalDatabase(sqlite); this.goalDatabase = new GoalDatabase(sqlite); // only do this if doesn exist. will clear existing selected goals. loadSelectedGoalsFromDb(); ViewSelectedGoalCommand = new MvxCommand <SelectedGoal>(selectedSelectedGoal => { ShowViewModel <GoalUpdateViewModel>(new { selectedGoalId = selectedSelectedGoal.Id }); } ); }
public MainPageViewModel(GoalDatabase goalDatabase, INavigationService navigationService) { _goalDatabase = goalDatabase; _navigationService = navigationService; this.Todo = new ObservableCollection <GroupedGoals>(); this.Completed = new ObservableCollection <Goal>(); this.NoCompleted = true; this.HasCompleted = false; _morningGoals = new GroupedGoals("Morning", "AM"); _afternoonGoals = new GroupedGoals("Afternoon", "PM"); _eveningGoals = new GroupedGoals("Evening", "PM"); this.Todo.Add(_morningGoals); this.Todo.Add(_afternoonGoals); this.Todo.Add(_eveningGoals); this.Completed.CollectionChanged += Completed_CollectionChanged; this.AddCommand = new Command(async() => { await _navigationService.NavigateToEditAsync(); }); this.EditCommand = new Command(async(obj) => { await _navigationService.NavigateToEditAsync((int)obj); }); this.DeleteCommand = new Command(async(obj) => { int goalId = (int)obj; await _goalDatabase.DeactivateGoal(goalId); Completed.Remove(Completed.FirstOrDefault(g => g.Id == goalId)); RemoveGoalFromToDoList(goalId); DependencyService.Get <INotificationManager>().Cancel(goalId); }); this.CompleteCommand = new Command(async(obj) => { int goalId = (int)obj; var goal = await _goalDatabase.GetGoalAsync(goalId); var updatedGoal = await _goalDatabase.AddGoalCompletion(goal, DateTime.Now); RemoveGoalFromToDoList(goalId); Completed.Add(updatedGoal); }); this.UndoCompleteCommand = new Command(async(obj) => { int goalId = (int)obj; var goal = await _goalDatabase.GetGoalAsync(goalId); var updatedGoal = await _goalDatabase.UndoGoalCompletion(goalId); Completed.Remove(Completed.FirstOrDefault(g => g.Id == goalId)); AddGoalToToDoList(new GoalViewModel(updatedGoal)); }); }
public EditGoal() { InitializeComponent(); _goalDb = new GoalDatabase(); }
public GoalUpdateViewModel(ISqlite sqlite) { this.selectedGoalDatabase = new SelectedGoalDatabase(sqlite); this.goalDatabase = new GoalDatabase(sqlite); }
public App() { InitializeComponent(); _goalDb = new GoalDatabase(); MainPage = new NavigationPage(new MainPage()); }