public WorkingLogDetailPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                             WorkingLogDetailService workingLogDetailService, ProjectService projectService,
                                             RefreshTokenService refreshTokenService,
                                             SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService       = navigationService;
            this.dialogService           = dialogService;
            this.workingLogDetailService = workingLogDetailService;
            this.projectService          = projectService;
            this.refreshTokenService     = refreshTokenService;
            this.systemStatusService     = systemStatusService;
            this.appStatus = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject          = new WorkingLogDetailDto();
                fooObject.WorkingLogId = MasterItem.Id;
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                paras.Add(MagicStringHelper.MasterRecordActionName, MasterItem);
                await navigationService.NavigateAsync("WorkingLogDetailRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                paras.Add(MagicStringHelper.MasterRecordActionName, MasterItem);
                await navigationService.NavigateAsync("WorkingLogDetailRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion
        }
        public WorkingLogPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                       WorkingLogService workingLogService, ProjectService projectService,
                                       MyUserService myUserService, WorkingLogDetailService workingLogDetailService,
                                       RefreshTokenService refreshTokenService,
                                       SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService       = navigationService;
            this.dialogService           = dialogService;
            this.workingLogService       = workingLogService;
            this.projectService          = projectService;
            this.myUserService           = myUserService;
            this.workingLogDetailService = workingLogDetailService;
            this.refreshTokenService     = refreshTokenService;
            this.systemStatusService     = systemStatusService;
            this.appStatus = appStatus;

            #region 新增紀錄
            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject     = new WorkingLogDto();
                fooObject.LogDate = DateTime.Now.Date;

                #region 設定該使用者為預設紀錄申請者
                var myUser = myUserService.Items
                             .FirstOrDefault(x => x.Id == appStatus.SystemStatus.UserID);
                if (myUser != null)
                {
                    fooObject.MyUserId   = myUser.Id;
                    fooObject.MyUserName = myUser.Name;
                }
                #endregion

                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudAddAction);
                await navigationService.NavigateAsync("WorkingLogRecordPage", paras);
            });
            #endregion

            #region 點選某筆紀錄觸發命令
            ItemTappedCommand = new DelegateCommand(async() =>
            {
                NavigationParameters paras = new NavigationParameters();
                var fooObject = SelectedItem.Clone();
                paras.Add(MagicStringHelper.CurrentSelectdItemParameterName, fooObject);
                paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudEditAction);
                await navigationService.NavigateAsync("WorkingLogRecordPage", paras);
            });
            #endregion

            #region 更新遠端紀錄命令
            RefreshCommand = new DelegateCommand(async() =>
            {
                IsRefresh = true;
                await ReloadData();
                IsRefresh = false;
            });
            #endregion

            #region 顯示明細頁面
            ShowDetailCommand = new DelegateCommand <WorkingLogDto>(async x =>
            {
                #region 讀取該筆明細清單
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 取得 專案清單
                    fooIProgressDialog.Title = "請稍後,取得 專案清單";
                    var apiResultssss        = await projectService.GetAsync();
                    if (apiResultssss.Status == true)
                    {
                        await projectService.WriteToFileAsync();
                    }
                    else
                    {
                        await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);
                        return;
                    }
                    #endregion

                    #region 取得 工作日誌明細
                    fooIProgressDialog.Title = "請稍後,取得 工作日誌明細";
                    apiResultssss            = await workingLogDetailService.GetAsync(x.Id);
                    if (apiResultssss.Status == true)
                    {
                        await workingLogDetailService.WriteToFileAsync();

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.MasterRecordActionName, x);
                        await navigationService.NavigateAsync("WorkingLogDetailPage", paras);
                    }
                    else
                    {
                        await DialogHelper.ShowAPIResultIsFailureMessage(dialogService, apiResultssss);
                        return;
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }
        public WorkingLogDetailRecordPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                                   WorkingLogDetailService workingLogDetailService, ProjectService projectService,
                                                   RefreshTokenService refreshTokenService,
                                                   SystemStatusService systemStatusService, AppStatus appStatus)
        {
            this.navigationService       = navigationService;
            this.dialogService           = dialogService;
            this.workingLogDetailService = workingLogDetailService;
            this.projectService          = projectService;
            this.refreshTokenService     = refreshTokenService;
            this.systemStatusService     = systemStatusService;
            this.appStatus = appStatus;

            #region 新增 儲存 按鈕命令
            SaveCommand = new DelegateCommand(async() =>
            {
                #region 進行資料完整性檢查
                var checkResult = SelectedItem.Validation();
                if (!string.IsNullOrEmpty(checkResult))
                {
                    await dialogService.DisplayAlertAsync("錯誤", $"請檢查並且修正錯誤{Environment.NewLine}{Environment.NewLine}" +
                                                          $"{checkResult}", "確定");
                    return;
                }
                #endregion

                #region 進行記錄儲存
                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,儲存資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    if (CrudAction == MagicStringHelper.CrudAddAction)
                    {
                        #region 新增 工作日誌明細紀錄
                        fooIProgressDialog.Title = "請稍後,新增 工作日誌明細紀錄";
                        SelectedItem.Id          = 0;
                        apiResult = await workingLogDetailService.PostAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"工作日誌明細紀錄 已經新增");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"工作日誌明細紀錄 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }
                    else
                    {
                        #region 儲存 工作日誌明細紀錄
                        fooIProgressDialog.Title = "請稍後,儲存 工作日誌明細紀錄";
                        apiResult = await workingLogDetailService.PutAsync(SelectedItem);
                        if (apiResult.Status == true)
                        {
                            ToastHelper.ShowToast($"工作日誌明細紀錄 已經儲存");

                            NavigationParameters paras = new NavigationParameters();
                            paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                            await navigationService.GoBackAsync(paras);
                        }
                        else
                        {
                            await dialogService.DisplayAlertAsync("錯誤", $"工作日誌明細紀錄 儲存失敗:{apiResult.Message}", "確定");
                        }
                        #endregion
                    }

                    #region 取得 工作日誌明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 工作日誌明細紀錄";
                    apiResult = await workingLogDetailService.GetAsync(MasterItem.Id);
                    if (apiResult.Status == true)
                    {
                        await workingLogDetailService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 工作日誌明細紀錄 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion

            #region 刪除 按鈕命令
            DeleteCommand = new DelegateCommand(async() =>
            {
                #region 進行記錄刪除
                var confirm = await dialogService.DisplayAlertAsync(
                    "警告", "是否要刪除這筆紀錄?", "確定", "取消");
                if (confirm == false)
                {
                    return;
                }

                APIResult apiResult = new APIResult();
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,刪除資料中...",
                                                                                         null, null, true, MaskType.Black))
                {
                    await AppStatusHelper.ReadAndUpdateAppStatus(systemStatusService, appStatus);
                    #region 檢查 Access Token 是否還可以使用
                    bool refreshTokenResult = await RefreshTokenHelper
                                              .CheckAndRefreshToken(dialogService, refreshTokenService,
                                                                    systemStatusService, appStatus);
                    if (refreshTokenResult == false)
                    {
                        return;
                    }
                    #endregion

                    #region 刪除 工作日誌明細紀錄
                    fooIProgressDialog.Title = "請稍後,刪除 工作日誌明細紀錄";
                    apiResult = await workingLogDetailService.DeleteAsync(SelectedItem);
                    if (apiResult.Status == true)
                    {
                        ToastHelper.ShowToast($"工作日誌明細紀錄 已經刪除");

                        NavigationParameters paras = new NavigationParameters();
                        paras.Add(MagicStringHelper.CrudActionName, MagicStringHelper.CrudRefreshAction);
                        await navigationService.GoBackAsync(paras);
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"工作日誌明細紀錄 刪除失敗:{apiResult.Message}", "確定");
                    }
                    #endregion

                    #region 取得 工作日誌明細紀錄
                    fooIProgressDialog.Title = "請稍後,取得 工作日誌明細紀錄";
                    apiResult = await workingLogDetailService.GetAsync(MasterItem.Id);
                    if (apiResult.Status == true)
                    {
                        await workingLogDetailService.WriteToFileAsync();
                    }
                    else
                    {
                        await dialogService.DisplayAlertAsync("錯誤", $"取得 工作日誌明細紀錄 失敗:{apiResult.Message}", "確定");
                    }
                    #endregion
                }
                #endregion
            });
            #endregion
        }