Exemple #1
0
        /// <summary>
        /// ViewModel 資料初始化
        /// </summary>
        /// <returns></returns>
        private async Task ViewModelInit()
        {
            var fooItems = await PCLGlobalHelper.foo使用者工作內容Repository.Read();

            UserTasksList.Clear();
            foreach (var item in fooItems)
            {
                AddViewModel(item);
            }
            await Task.Delay(100);
        }
Exemple #2
0
        public MainPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator,
                                 IPageDialogService dialogService)
        {
            #region 相依性服務注入的物件

            _dialogService     = dialogService;
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            #endregion

            #region 頁面中綁定的命令
            DoRefreshCommand = new DelegateCommand(async() =>
            {
                fooAPIResult = await PCLGlobalHelper.foo使用者工作內容Repository.GetDateRangeAsync(
                    PCLGlobalHelper.foo使用者登入Repository.Item.Account);

                if (fooAPIResult.Success == true)
                {
                    UserTasksList.Clear();
                    foreach (var item in PCLGlobalHelper.foo使用者工作內容Repository.Items)
                    {
                        AddViewModel(item);
                    }
                }
                else
                {
                    await _dialogService.DisplayAlertAsync("警告", fooAPIResult.Message, "確定");
                }
                IsRefreshing = false;
            });

            ItemTappedCommand = new DelegateCommand(async() =>
            {
                await _navigationService.NavigateAsync($"TaskEditPage?ID={UserTasksListSelected.Id}");
            });
            #endregion

            #region 事件聚合器訂閱
            //訂閱是否要更新這個 ListView 的資料內容之事件
            _eventAggregator.GetEvent <TaskRefreshEventEvent>().Subscribe(async x =>
            {
                await ViewModelInit();
            });
            #endregion
        }
        public MainPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator,
                                 IPageDialogService dialogService)
        {
            #region 相依性服務注入的物件

            _dialogService     = dialogService;
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            #endregion

            #region 頁面中綁定的命令
            DoRefreshCommand = new DelegateCommand(async() =>
            {
                // 這裡使用 UserDialogs 顯示一個正在忙碌中的處理遮罩
                using (Acr.UserDialogs.UserDialogs.Instance.Loading($"請稍後,正在取回最新派工紀錄中...", null, null, true, Acr.UserDialogs.MaskType.Black))
                {
                    fooAPIResult = await PCLGlobalHelper.foo使用者工作內容Repository.GetDateRangeAsync(
                        PCLGlobalHelper.foo使用者登入Repository.Item.Account);

                    if (fooAPIResult.Success == true)
                    {
                        UserTasksList.Clear();
                        foreach (var item in PCLGlobalHelper.foo使用者工作內容Repository.Items)
                        {
                            AddViewModel(item);
                        }
                    }
                    else
                    {
                        await _dialogService.DisplayAlertAsync("警告", fooAPIResult.Message, "確定");
                    }
                    IsRefreshing = false;
                }
            });

            ItemTappedCommand = new DelegateCommand(async() =>
            {
                await _navigationService.NavigateAsync($"TaskEditPage?ID={UserTasksListSelected.Id}");
            });
            #endregion

            #region 事件聚合器訂閱
            #endregion
        }
Exemple #4
0
        public TaskHistoryPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator,
                                        IPageDialogService dialogService)
        {
            #region 相依性服務注入的物件

            _dialogService     = dialogService;
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            #endregion

            #region 頁面中綁定的命令
            DoRefreshCommand = new DelegateCommand(async() =>
            {
                fooAPIResult = await PCLGlobalHelper.foo使用者歷史工作內容Repository.GetDateRangeAsync(
                    PCLGlobalHelper.foo使用者登入Repository.Item.Account, DateTime.Now.AddDays(-7), DateTime.Now);

                if (fooAPIResult.Success == true)
                {
                    UserTasksList.Clear();
                    foreach (var item in PCLGlobalHelper.foo使用者歷史工作內容Repository.Items)
                    {
                        AddViewModel(item);
                    }
                }
                else
                {
                    await _dialogService.DisplayAlertAsync("警告", fooAPIResult.Message, "確定");
                }
                IsRefreshing = false;
            });

            ItemTappedCommand = new DelegateCommand(async() =>
            {
                await _navigationService.NavigateAsync($"TaskHistoryDetailPage?ID={UserTasksListSelected.Id}");
            });
            #endregion

            #region 事件聚合器訂閱

            #endregion
        }
        protected async Task ExecuteLoadItemsCommand()
        {
            if (IsBusy)
            {
                return;
            }
            IsBusy = true;
            try
            {
                if (UserTasksList == null)
                {
                    UserTasksList = new ObservableCollection <UserTaskViewModel>();
                }
                else
                {
                    UserTasksList.Clear();
                }

                int[] status =
                {
                    UserTaskStatus.Active, UserTaskStatus.Pending, UserTaskStatus.Paused, UserTaskStatus.Aborted
                };

                var userTasks = await _userTaskService.GetAllUserTaskByUserID(App.CurrentLogInUser.Email, status);

                foreach (var usertask in userTasks)
                {
                    var userTaskTime = await _userTaskService.GetUserTaskTimeByUserTaskId(usertask.UserTaskID);

                    UserTasksList.Add(new UserTaskViewModel(usertask, userTaskTime));
                }
            }
            finally
            {
                IsBusy = false;
            }
        }