private void Button_Click_BackToHomePage(object sender, RoutedEventArgs e)
        {
            //Back to home button
            UserHomePage homePage = new UserHomePage();

            this.NavigationService?.Navigate(homePage);
        }
Esempio n. 2
0
        private void Button_Click_Login(object sender, RoutedEventArgs e)
        {
            using (var context = new EverydayJournalContext())
            {
                //Getting username and password from the login form
                var username = UsernameInput.Text;
                var password = PasswordInput.Password;

                //Check if the data successfully match in the database
                if (context.People.Any(a => a.Password == password && a.Name == username))
                {
                    var userId = context.People
                                 .Where(a => a.Password == password && a.Name == username)
                                 .Select(i => new { i.Id, i.Name })
                                 .FirstOrDefault();

                    MessageBox.Show("Successfully logged!");
                    //Saving Id and UserName for the current session.
                    LoggerUtility.UserId   = userId.Id;
                    LoggerUtility.UserName = userId.Name;

                    //Navigate to UserHomePage

                    UserHomePage userHomePage = new UserHomePage();
                    this.NavigationService?.Navigate(userHomePage);
                }
                else
                {
                    //Invalid credentials
                    MessageBox.Show("Invalid Username or Password!");
                    UsernameInput.Clear();
                    PasswordInput.Clear();
                }
            }
        }
Esempio n. 3
0
        private void RegisterSubmit_Click(object sender, RoutedEventArgs e)
        {
            //Getting the data from the page
            var name     = NameInput.Text;
            var password = PasswordInput.Password;
            var email    = EmailInput.Text;

            //Check before using adding to DB
            if (name.Length < 4)
            {
                MessageBox.Show("The name should be greater than 3 symbols!");
            }
            else if (password.Length < 5)
            {
                MessageBox.Show("The password should be greater than 4 symbols!");
            }
            else if (!email.Contains("@") || email.Length < 6)
            {
                MessageBox.Show("Invalid Email!");
            }
            else
            {
                using (var context = new EverydayJournalContext())
                {
                    try
                    {
                        context.People
                        .Add(new Person()
                        {
                            Name     = name,
                            Password = password,
                            Email    = email
                        });

                        context.SaveChanges();
                        MessageBox.Show("Registration successful!");

                        //Saving Id and UserName for the current session.
                        LoggerUtility.UserId   = context.People.Where(n => n.Name == name).Select(x => x.Id).FirstOrDefault();
                        LoggerUtility.UserName = name;

                        UserHomePage homePage = new UserHomePage();
                        this.NavigationService?.Navigate(homePage);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Error with registering. Please, try again!");
                        NameInput.Clear();
                        PasswordInput.Clear();
                        EmailInput.Clear();
                    }
                }
            }
        }
        private void Button_Click_SaveChanges(object sender, RoutedEventArgs e)
        {
            using (var context = new EverydayJournalContext())
            {
                //Getting current values of the text boxes
                var username             = UsernameChange.Text;
                var email                = EmailChange.Text;
                var password             = Password.Password;
                var passwordConfirmation = ConfirmPassword.Password;
                //Getting user from DB
                var userPassword = context.People.Find(LoggerUtility.UserId);

                if (password == passwordConfirmation &&
                    userPassword?.Password == password &&
                    username.Length > 3 &&
                    email.Length > 3)
                {
                    try
                    {
                        //Updating the user
                        userPassword.Name  = username;
                        userPassword.Email = email;

                        context.SaveChanges();

                        MessageBox.Show("Successfully updated information!");

                        UserHomePage userHomePage = new UserHomePage();
                        this.NavigationService?.Navigate(userHomePage);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Please, try again with correct information!");
                        EmailChange.Clear();
                        UsernameChange.Clear();
                        Password.Clear();
                        ConfirmPassword.Clear();
                    }
                }
                else
                {
                    MessageBox.Show(
                        "Invalid data. Please, try with correct password and Username/Email greater than 4 symbols!");
                }
            }
        }
        private void Button_Click_BackToMainMenu(object sender, RoutedEventArgs e)
        {
            UserHomePage homePage = new UserHomePage();

            this.NavigationService?.Navigate(homePage);
        }