Exemplo n.º 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");
            });
        }
        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
        }
        public MDPageViewModel(INavigationService navigationService,
                               IPageDialogService dialogService, MyUserService myUserService,
                               LoginService loginService, SystemStatusService systemStatusService,
                               AppStatus appStatus, RecordCacheHelper recordCacheHelper,
                               LogoutCleanHelper logoutCleanHelper)
        {
            this.navigationService   = navigationService;
            this.dialogService       = dialogService;
            this.myUserService       = myUserService;
            this.loginService        = loginService;
            this.systemStatusService = systemStatusService;
            this.appStatus           = appStatus;
            this.recordCacheHelper   = recordCacheHelper;
            this.logoutCleanHelper   = logoutCleanHelper;

            #region 一般命令
            MenuCommand = new DelegateCommand <string>(async x =>
            {
                switch (x)
                {
                case "首頁":
                    await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
                    break;
                }
            });
            #endregion

            #region 登出命令
            LogoutCommand = new DelegateCommand(async() =>
            {
                var isLogout = await dialogService.DisplayAlertAsync("警告",
                                                                     "你確定要登出嗎?", "確定", "取消");
                if (isLogout == true)
                {
                    using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
                    {
                        await logoutCleanHelper.LogoutCleanAsync(fooIProgressDialog);
                        var fooResult = await LoginUpdateTokenHelper.UserLogoutAsync(dialogService, loginService, systemStatusService, appStatus);
                        if (fooResult == true)
                        {
                            await navigationService.NavigateAsync("/LoginPage");
                        }
                    }
                }
            });
            #endregion
        }
Exemplo n.º 4
0
 public MDPageViewModel(INavigationService navigationService, IPageDialogService dialogService,
                        LoginManager loginManager, SystemStatusManager systemStatusManager,
                        AppStatus appStatus, LogoutCleanHelper logoutCleanHelper)
 {
     this.navigationService   = navigationService;
     this.dialogService       = dialogService;
     this.loginManager        = loginManager;
     this.systemStatusManager = systemStatusManager;
     this.appStatus           = appStatus;
     this.logoutCleanHelper   = logoutCleanHelper;
     HomeCommand = new DelegateCommand(async() =>
     {
         await navigationService.NavigateAsync("/MDPage/NaviPage/HomePage");
     });
     SuggestionCommand = new DelegateCommand(async() =>
     {
         await navigationService.NavigateAsync("/MDPage/NaviPage/SuggestionPage");
     });
     ExceptionCommand = new DelegateCommand(() =>
     {
         throw new Exception("發生了一個自訂的例外異常");
     });
     UserGroupCommand = new DelegateCommand(async() =>
     {
         await navigationService.NavigateAsync("/MDPage/NaviPage/CommUsePage");
     });
     LeaveFormCommand = new DelegateCommand(async() =>
     {
         await navigationService.NavigateAsync("/MDPage/NaviPage/LeaveFormPage");
     });
     LogoutCommand = new DelegateCommand(async() =>
     {
         using (IProgressDialog fooIProgressDialog = UserDialogs.Instance.Loading($"請稍後,更新資料中...", null, null, true, MaskType.Black))
         {
             await logoutCleanHelper.LogoutCleanAsync(fooIProgressDialog);
             var fooResult = await LoginUpdateTokenHelper.UserLogoutAsync(dialogService, loginManager, systemStatusManager, appStatus);
             if (fooResult == true)
             {
                 await navigationService.NavigateAsync("/LoginPage");
             }
         }
     });
 }