Esempio n. 1
0
        public LoginViewModel()
        {
            if (IsInDesignMode)
                return;

            settingsRepository = SimpleIoc.Default.GetInstance<IUserInfoSettingsRepository>();
            dialogService = SimpleIoc.Default.GetInstance<IDialogService>();
            client = SimpleIoc.Default.GetInstance<IClient>();
            client.ErrorOccurred += ClientOnErrorOccurred;

            UserInfo = settingsRepository.GetSettings();

            if (UserInfo == null)
                UserInfo = new UserInfo();
            else
                RememberMe = true;
                Login = new RelayCommand(() =>
                   {
                       Messenger.Default.Send(new NotificationMessage(Messages.ShowWaitWindow));

                       client.LoginAsync(UserInfo.ServerAddress, UserInfo.Username, UserInfo.Password, (success) =>
                                                                                                           {
                                                                                                               client.ErrorOccurred -= ClientOnErrorOccurred;

                                                                                                               Messenger.Default.Send(new NotificationMessage(Messages.DismissWaitWindow));

                                                                                                               if (success)
                                                                                                               {
                                                                                                                   settingsRepository.SetSettings(RememberMe ? UserInfo : null);
                                                                                                                   Messenger.Default.Send(new NotificationMessage(Messages.NavigateToMainWindow));
                                                                                                               }
                                                                                                               else
                                                                                                               {
                                                                                                                   dialogService.ShowMessageBox("Authentication error", "Warn", MessageBoxButton.OK, MessageBoxImage.Warning);
                                                                                                               }
                                                                                                           });

                   }, () => UserInfo.IsValid);
        }
        public LoginViewModel()
        {
            _userSettingsRepository = GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.GetInstance<IUserInfoSettingsRepository>();
            _settingsRepository = GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.GetInstance<IGenericSettingsRepository<AppPreferences>>();

            UserInfo = _userSettingsRepository.GetSettings();
            var settings = _settingsRepository.GetSettings();

            if (UserInfo == null)
            {
                UserInfo = new UserInfo();
                if (settings == null)
                    UserInfo.ServerAddress = string.Format("{0}:{1}", WcfConnectionProperties.Default.Address,
                                                           WcfConnectionProperties.Default.Port);
                else
                    UserInfo.ServerAddress = string.Format("{0}:{1}", settings.ConnectionProperties.Address,
                                                           settings.ConnectionProperties.Port);
            }
            else
                RememberMe = true;

            InitCommands();
            InitView();
        }