コード例 #1
0
        public LoginPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                  LoginManager loginManager, SystemStatusManager systemStatusManager,
                                  AppStatus appStatus, RecordCacheHelper recordCacheHelper)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.loginManager        = loginManager;
            this.systemStatusManager = systemStatusManager;
            this.appStatus           = appStatus;
            this.recordCacheHelper   = recordCacheHelper;
            LoginCommand             = new DelegateCommand(async() =>
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
                {
                    LoginRequestDTO loginRequestDTO = new LoginRequestDTO()
                    {
                        Account  = Account,
                        Password = Password,
                    };
                    var fooResult = await LoginUpdateTokenHelper.UserLoginAsync(dialogService, loginManager, systemStatusManager,
                                                                                loginRequestDTO, appStatus);
                    if (fooResult == false)
                    {
                        return;
                    }
                    await recordCacheHelper.RefreshAsync(fooIProgressDialog);
                }

                //await dialogService.DisplayAlertAsync("Info", "登入成功", "OK");
                await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
            });
        }
コード例 #2
0
        public LoginPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                                  LoginService loginService, MyUserService myUserService, SystemStatusService systemStatusService,
                                  AppStatus appStatus, RecordCacheHelper recordCacheHelper)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.loginService        = loginService;
            this.myUserService       = myUserService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;
            this.recordCacheHelper   = recordCacheHelper;

            #region 登入按鈕命令
            LoginCommand = new DelegateCommand(async() =>
            {
                using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,使用者登入驗證中...", null, null, true, MaskType.Black))
                {
                    LoginRequestDto loginRequestDTO = new LoginRequestDto()
                    {
                        Account  = Account,
                        Password = Password,
                    };
                    var fooResult = await LoginUpdateTokenHelper.UserLoginAsync(dialogService, loginService, systemStatusService,
                                                                                loginRequestDTO, appStatus);
                    if (fooResult == false)
                    {
                        await dialogService.DisplayAlertAsync("登入驗證失敗", "請重新輸入正確的帳號與密碼", "確定");
                        return;
                    }
                    await recordCacheHelper.RefreshAsync(fooIProgressDialog);
                    #region 取得 使用者清單
                    fooIProgressDialog.Title = "請稍後,取得 使用者清單";
                    await myUserService.ReadFromFileAsync();
                    APIResult apiResult = await myUserService.GetAsync();
                    if (apiResult.Status == true)
                    {
                        await myUserService.WriteToFileAsync();
                    }
                    #endregion
                }

                await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
            });
            #endregion

            #region 切換使用者
            SwitchUserCommand = new DelegateCommand <string>(x =>
            {
                Account = x;
            });
            #endregion
        }