private void TaskComepleted(UserTaskViewModel userTaskVm) { if (UserTasksList != null) { UserTasksList.Remove(userTaskVm); } }
void AddViewModel(UserTasks userTask) { UserTasksVM fooUserTasksVM = new UserTasksVM { Account = userTask.Account, CheckinDatetime = userTask.CheckinDatetime, CheckinId = userTask.CheckinId, Checkin_Latitude = userTask.Checkin_Latitude, Checkin_Longitude = userTask.Checkin_Longitude, Condition1_Result = userTask.Condition1_Result, Condition1_Ttile = userTask.Condition1_Ttile, Condition2_Result = userTask.Condition2_Result, Condition2_Ttile = userTask.Condition2_Ttile, Condition3_Result = userTask.Condition3_Result, Condition3_Ttile = userTask.Condition3_Ttile, Description = userTask.Description, Id = userTask.Id, PhotoURL = userTask.PhotoURL, Reported = userTask.Reported, ReportedDatetime = userTask.ReportedDatetime, Status = userTask.Status, TaskDateTime = userTask.TaskDateTime, Title = userTask.Title, }; UserTasksList.Add(fooUserTasksVM); }
/// <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); }
private async Task <bool> CreateUserTask(UserTask newUserTask) { var newTask = await _userTaskService.CreateUserTask(newUserTask); UserTasksList.Insert(0, new UserTaskViewModel(newTask, new List <UserTaskTime>())); this.Publish <UserTaskStatusChanged>(); await UpdateRequestedBy(newTask); return(true); }
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 }
private async Task UpdateRequestedBy(UserTask userTask) { var requestedBy = await _clientContactService.GetContactBy(userTask.ClientID); if (requestedBy == null) { return; } var userTaskModel = UserTasksList.FirstOrDefault(c => c.UserTask.UserTaskID == userTask.UserTaskID); if (userTaskModel != null) { userTaskModel.UserTask.RequestedBy = requestedBy.Name; await _userTaskService.UpdateUserTask(userTaskModel.UserTask); } }
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 }
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; } }
void AddViewModel(UserTasks userTask) { UserTasksList.Add(userTask); }