Beispiel #1
0
        public OfflineOrOnlineAdminstrationChoseViewmodel(IView view)
        {
            _view = view;



            OfflineCommand = new RelayCommand(async(object obj) =>
            {
                _view.Disable();

                SQLiteStarter starter             = new SQLiteStarter();
                IUserProvider desktopUserProvider = ServiceResolver.GetContainer().GetInstance <IUserProvider>();
                desktopUserProvider.SetUserId(LoginRepository.Instance.CurrentUser.ID);
                starter.CreateDBIfNotExists();
                // starter.TestSeedDb();
                Properties.Settings settings = new Properties.Settings();
                if (RememberChoice)
                {
                    settings.ChoiceIsOnline       = false;
                    settings.RememberOnlineChoice = true;
                    settings.Save();
                }
                else
                {
                    settings.RememberOnlineChoice = false;
                    settings.Save();
                }

                await RepositoryResolver.GetRepository <ITransactionRepository>().CreateInitialFilling();

                new MainWindow().Show();
                _view.Close();
            });
        }
Beispiel #2
0
        public async Task <LoginResult> Login(string emailAdress, string password)
        {
            LoginResult result      = new LoginResult();
            var         credentials = CredentialUtil.GetCredential("BalanceKeeper.Desktop" + emailAdress);

            if (emailAdress != null && credentials != null && credentials.Username == emailAdress && password == credentials.Password)
            {
                result.IsError = false;
                SetCurrentUser(emailAdress);


                SQLiteStarter starter = new SQLiteStarter();
                starter.Start(new Action(() =>
                {
                    IUserProvider desktopUserProvider = ServiceResolver.GetContainer().GetInstance <IUserProvider>();
                    desktopUserProvider.SetUserId(LoginRepository.Instance.CurrentUser.ID);
                }));
                starter.CreateDBIfNotExists();

                await RepositoryResolver.GetRepository <ITransactionRepository>().CreateInitialFilling();
            }
            else
            {
                result.IsError   = true;
                result.ErrorType = LoginErrorType.WrongCredentials;
            }
            return(await Task <LoginResult> .FromResult(result));
        }
Beispiel #3
0
        public LoginViewmodel(IView view)
        {
            Properties.Settings settings = new Properties.Settings();
            EmailAdress = settings.LastUsername;
            ServiceResolver.GetContainer().Register <IUserProvider, DesktopUserProvider>(Lifestyle.Singleton);

            LoginTaskNotifier    = new NotifyTaskCompletion <LoginResult>(Task.FromResult <LoginResult>(null));
            RegisterTaskNotifier = new NotifyTaskCompletion <RegisterResult>(Task.FromResult <RegisterResult>(null));
            _view        = view;
            CloseCommand = new RelayCommand((object obj) =>
            {
                Environment.Exit(0);
            });


            LoginCommand = new RelayCommand((object obj) =>
            {
                PasswordBox passBox = obj as PasswordBox;

                if (!string.IsNullOrWhiteSpace(EmailAdress) && !string.IsNullOrWhiteSpace(passBox.Password))
                {
                    passBox.SelectAll();
                    StartLogin(EmailAdress, passBox.Password);
                }
            });

            RegisterCommand = new RelayCommand((object obj) =>
            {
                if (IsRegistering && !string.IsNullOrWhiteSpace(EmailAdress))
                {
                    var loginView = obj as LoginView;
                    ErrorMessage  = string.Empty;
                    if (loginView.PassBoxReg1.Password != loginView.PassBoxReg2.Password)
                    {
                        ErrorMessage = "Wachtwoorden komen niet overeen";
                    }

                    if (ErrorMessage == string.Empty)
                    {
                        lastPassword         = loginView.PassBoxReg1.Password;
                        RegisterTaskNotifier = new NotifyTaskCompletion <RegisterResult>(LoginRepository.Instance.Register(EmailAdress, loginView.PassBoxReg1.Password), CompletedRegistration);
                    }
                }
                else
                {
                    IsRegistering = true;
                }
            });

            CancelRegisterCommand = new RelayCommand((object obj) =>
            {
                IsRegistering = false;
            });
        }
Beispiel #4
0
        public void CreateDBIfNotExists()
        {
            SQLiteDatabaseContext context = ServiceResolver.GetContainer().GetInstance <IDataProvider>() as SQLiteDatabaseContext;

            //context.Database.ExecuteSqlCommand("DELETE FROM Transactions");
#if DEBUG
            context.Database.EnsureDeleted();
#endif
            context.Database.EnsureCreated();
            context.Database.Migrate();
            context.SaveChanges();
        }
Beispiel #5
0
        public override void Start(Action initializeUserRepository)
        {
            UseLifestyle = Lifestyle.Singleton;

            base.Start(initializeUserRepository);

            Directory.CreateDirectory(BuildFolderPath());
            ServiceResolver.GetContainer().Register <IDataProvider>(() =>
            {
                initializeUserRepository.Invoke();
                DatabaseStarter.RegisterDatatabaseRepositories();
                return(new SQLiteDatabaseContext(BuildConnectionString()));
            }, Lifestyle.Singleton);
        }