private void Registration_Click(object sender, RoutedEventArgs e) { if (name.Text != "") { if (email.Text != "") { if (EMailCheck(email.Text)) { if (password.Password != "") { try { using (var context = new Context()) { var encrypt = new Encryption(); if (!context.Users.Any(u => u.Email == email.Text)) { User user = new User { FullName = name.Text, Email = email.Text, Password = encrypt.GetHash(password.Password) }; context.Users.AddOrUpdate(user); foreach (var hierogl in context.Hieroglyphs) { context.Favourites.AddOrUpdate(new Favourite { Hieroglyph = hierogl.ChineseWord, TaskOneRight = false, TaskTwoRight = false, TaskThreeRight = false, UserMail = user.Email }); } ; context.SaveChanges(); var logIn = new LogIn(); logIn.Show(); this.Close(); } else { MessageBox.Show("This email is already registered, please choose another"); } } } catch (Exception) { MessageBox.Show("Please check", "Something's wrong with the DataBase!"); throw; } } else { MessageBox.Show("Enter your password!"); } } else { MessageBox.Show("Invalid Email"); } } else { MessageBox.Show("Enter your Email!"); } } else { MessageBox.Show("Enter your name!"); } }