Exemplo n.º 1
0
        private async void DeleteNoteExecute(object o)
        {
            LoaderManager.ShowLoader();
            await Task.Run(() =>
            {
                if (SelectedNote == null)
                {
                    return;
                }

                StationManager.CurrentUser.Notes.RemoveAll(uwr => uwr.Guid == SelectedNote.Guid);
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    DBManager.DeleteNote(SelectedNote.Note);
                    FillNotes();
                    if (Notes.Count < 1)
                    {
                        SelectedNote = null;
                    }
                    OnPropertyChanged(nameof(SelectedNote));
                    OnPropertyChanged(nameof(Notes));
                });
            });

            LoaderManager.HideLoader();
        }
Exemplo n.º 2
0
        private async void LoginCommandImpl(object arg)
        {
            var passBox = arg as PasswordBox;

            if (passBox == null)
            {
                return;
            }
            LoaderManager.ShowLoader();
            var isLoggedIn = await AccountManager.SignIn(Login, passBox.Password);

            LoaderManager.HideLoader();

            // If user exists and password is correct
            if (isLoggedIn)
            {
                NavigationManager.Navigate(Managers.Screens.Main);
                // Clear fields if success
                Login            = "";
                passBox.Password = "";
            }
            else
            {
                MessageBox.Show("Can't login to account.");
            }
        }
Exemplo n.º 3
0
        private async void RemoveReminding(ReminderData data)
        {
            LoaderManager.ShowLoader();
            await AccountManager.DeleteReminding(data);

            FillNotifications();
            LoaderManager.HideLoader();
            EditorVisibility = Visibility.Hidden;
        }
Exemplo n.º 4
0
        private async void ChangeNotification(ReminderData data)
        {
            LoaderManager.ShowLoader();
            await AccountManager.UpdateReminding(data);

            //TODO optimize
            FillNotifications();
            LoaderManager.HideLoader();
            EditorVisibility = Visibility.Hidden;
        }
Exemplo n.º 5
0
        private async void EditNoteExecute(KeyEventArgs args)
        {
            LoaderManager.ShowLoader();
            await Task.Run(() =>
            {
                DBManager.SaveNote(_currentNote.Note);
                OnPropertyChanged(nameof(Notes));
            });

            LoaderManager.HideLoader();
            MessageBox.Show("Note saved");
        }
Exemplo n.º 6
0
        private async void AddReminding(object arg)
        {
            ReminderData data = new ReminderData(AccountManager.CurrentUser)
            {
                SelectedDate = DateTime.Now.AddHours(1),
                ReminderText = ""
            };

            LoaderManager.ShowLoader();
            await AccountManager.AddReminding(data);

            FillNotifications();
            LoaderManager.HideLoader();
        }
Exemplo n.º 7
0
        private async void SignInExecute(object obj)
        {
            LoaderManager.ShowLoader();
            var result = await Task.Run(() =>
            {
                User currentUser;
                try
                {
                    currentUser = DBManager.GetUserByLogin(_login);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(Resources.SignIn_FailedToGetUser, Environment.NewLine,
                                                  ex.Message));
                    return(false);
                }
                if (currentUser == null)
                {
                    MessageBox.Show(String.Format(Resources.SignIn_UserDoesntExist, _login));
                    return(false);
                }
                try
                {
                    if (!currentUser.CheckPassword(_password))
                    {
                        MessageBox.Show(Resources.SignIn_WrongPassword);
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(Resources.SignIn_FailedToValidatePassword, Environment.NewLine,
                                                  ex.Message));
                    return(false);
                }
                StationManager.AddCurrentUserToCache(currentUser);
                return(true);
            });

            LoaderManager.HideLoader();
            if (result)
            {
                NavigationManager.Instance.Navigate(ModesEnum.Main);
            }
        }
Exemplo n.º 8
0
        private async void SignUpExecute(object obj)
        {
            LoaderManager.ShowLoader();
            var result = await Task.Run(() =>
            {
                try
                {
                    if (!new EmailAddressAttribute().IsValid(_email))
                    {
                        MessageBox.Show(String.Format(Resources.SignUp_EmailIsNotValid, _email));
                        return(false);
                    }
                    if (DBManager.UserExists(_login))
                    {
                        MessageBox.Show(String.Format(Resources.SignUp_UserAlreadyExists, _login));
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(Resources.SignUp_FailedToValidateData, Environment.NewLine, ex.Message));
                    return(false);
                }
                try
                {
                    var user = new User(_login, _firstName, _lastName, _email, _password);
                    DBManager.AddUser(user);
                    StationManager.CurrentUser = user;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(String.Format(Resources.SignUp_FailedToCreateUser, Environment.NewLine,
                                                  ex.Message));
                    return(false);
                }
                MessageBox.Show(String.Format(Resources.SignUp_UserSuccessfulyCreated, _login));
                return(true);
            });

            LoaderManager.HideLoader();
            if (result)
            {
                NavigationManager.Instance.Navigate(ModesEnum.Main);
            }
        }
Exemplo n.º 9
0
        private async void AddNoteExecute(object o)
        {
            LoaderManager.ShowLoader();
            await Task.Run(() =>
            {
                Note note = new Note("New Note", "", StationManager.CurrentUser);
                DBManager.AddNote(note);
                App.Current.Dispatcher.Invoke((Action) delegate
                {
                    var noteUIModel = new NoteUIModel(note);
                    _notes.Add(noteUIModel);
                    FillNotes();
                    SelectedNote = noteUIModel;
                });
            });

            LoaderManager.HideLoader();
        }
Exemplo n.º 10
0
        private async void Register(object obj)
        {
            UserData registrationData = new UserData
            {
                Login     = Login,
                Password  = Password,
                Name      = Name,
                Surname   = Surname,
                Email     = Email,
                LastLogin = DateTime.Now
            };

            try
            {
                LoaderManager.ShowLoader();
                bool hasRegistered = await AccountManager.SignUp(registrationData);

                if (!hasRegistered)
                {
                    MessageBox.Show("Can't register new user. Login already taken or server unavailable.");
                    throw new Exception("Can't register new user. Login already taken or server unavailable.");
                }
                //Clear inputs
                Login    = "";
                Password = "";
                Name     = "";
                Surname  = "";
                Email    = "";
                // Go to main screen
                NavigationManager.Navigate(Managers.Screens.Main);
            }
            catch (Exception e)
            {
                Logger.Log("Can't register new user", e);
            }
            finally
            {
                LoaderManager.HideLoader();
            }
        }