public MainWindowViewModel() { // Connect to database _DBGateway = new DatabaseGateway($"Data Source={App.databasePath};"); // Load all data _DBGateway.LoadAllData(); // Convert data to VMs ObservableCollection <TaskViewModel> taskItems = new ObservableCollection <TaskViewModel>(); ObservableCollection <WBSViewModel> wbsItems = new ObservableCollection <WBSViewModel>(); foreach (WBS wbsItem in _DBGateway.WBSs) { WBSViewModel wbsVM = new WBSViewModel(wbsItem, _DBGateway); wbsItems.Add(wbsVM); } foreach (TaskItem taskItem in _DBGateway.TaskItems) { TaskViewModel taskVM = new TaskViewModel(taskItem, _DBGateway); if (taskItem.WBSId != null) { foreach (WBSViewModel wbsVM in wbsItems) { if (taskItem.WBSId == wbsVM.WBSItem.WBSId) { taskVM.WBSVM = wbsVM; break; } } } taskItems.Add(taskVM); } TimerAsync ta = new TimerAsync(); ta.StartTimer(); // Add available pages PageViewModels.Add("task", new TaskPageViewModel(_DBGateway, taskItems, wbsItems, ta)); PageViewModels.Add("wbs", new WBSPageViewModel(_DBGateway, wbsItems, taskItems)); // Set starting page CurrentPageViewModel = PageViewModels["task"]; }
public TaskPageViewModel(DatabaseGateway dbGateway, ObservableCollection <TaskViewModel> taskVMs, ObservableCollection <WBSViewModel> wbsVMs, TimerAsync timer) { _dbGateway = dbGateway; _timer = timer; _notificationManager = new NotificationManager(); // Default tracking date is today TrackingDate = DateTime.UtcNow; WBSViewModels = wbsVMs; TaskViewModels = taskVMs; TaskViewModelsView = (CollectionView)CollectionViewSource.GetDefaultView(TaskViewModels); TaskViewModelsView.Filter = TaskDateFilter; UpdateTotalTime(); StartNotificationTracking(); }