protected static void RegisterWithValues(PALEntities db, string UserName, string Password, string EMail) { string Sha1Password = GetSha1HashData(Password); UserRegistration newUser = new UserRegistration { UserName = UserName, UserPassword = Sha1Password, UserEMail = EMail }; db.UserRegistrations.Add(newUser); db.SaveChanges(); ViewModel.ID = newUser.ID; UserPersonalInformation newUserPersonalInfo = new UserPersonalInformation { AvatarPicture = "http://i.imgur.com/xTMBZYr.jpg", UserRegID = ViewModel.ID }; db.SaveChanges(); db.UserPersonalInformations.Add(newUserPersonalInfo); UserGameInformation newUserGameInfo = new UserGameInformation { UserRegID = ViewModel.ID }; db.UserGameInformations.Add(newUserGameInfo); db.SaveChanges(); }
private void SaveChanges(object sender, RoutedEventArgs e) { PALEntities dataContex = new PALEntities(); UserPersonalInformation userPersonalInfo = GetUserById(dataContex, ViewModels.ViewModel.ID); if (!(string.IsNullOrEmpty(CityNameTextBox.Text) && string.IsNullOrWhiteSpace(CityNameTextBox.Text))) { userPersonalInfo.CityName = CityNameTextBox.Text; } if (!(string.IsNullOrEmpty(SchoolNameTextBox.Text) && string.IsNullOrWhiteSpace(SchoolNameTextBox.Text))) { userPersonalInfo.SchoolName = SchoolNameTextBox.Text; } if (!(string.IsNullOrEmpty(YearsOldTextBox.Text) && string.IsNullOrWhiteSpace(YearsOldTextBox.Text))) { userPersonalInfo.YearsOld = YearsOldTextBox.Text; } if (!(ClassComboBox.SelectedIndex < 0)) { ComboBoxItem cbItem = (ComboBoxItem)ClassComboBox.SelectedItem; userPersonalInfo.Class = cbItem.Content.ToString(); } if (!(SexComboBox.SelectedIndex < 0)) { //var editt = (TextBox)SexComboBox.Template.FindName("ClassComboBox", SexComboBox); ComboBoxItem cbItem = (ComboBoxItem)SexComboBox.SelectedItem; userPersonalInfo.Sex = cbItem.Content.ToString(); } dataContex.SaveChanges(); Switcher.Switch(Switcher.ProfileContentSwitcher, new ProfileContent()); }
protected static int LogInReturnId(string EMail, string Password) { Password = GetSha1HashData(Password); PALEntities db = new PALEntities(); return(db.UserRegistrations.Where(u => u.UserEMail == EMail && u.UserPassword == Password).Select(c => c.ID).SingleOrDefault()); }
private void HandleRegisterCommand(object parameter) { var commandParameterValues = (object[])parameter; var firstPass = commandParameterValues[0] as PasswordBox; var firstPassValue = firstPass.Password; var secondPass = commandParameterValues[1] as PasswordBox; var secondPassValue = secondPass.Password; var UEmail = commandParameterValues[2] as TextBox; var UserEMailValue = UEmail.Text; if (UserName == "" || UserEMailValue == "" || firstPassValue == "" || secondPassValue == "") { WPFMessageBox.MessageBox.ShowError("Не сте въвели всичките задължителни полета."); return; } if (Validation.GetHasError(secondPass) || Validation.GetHasError(UEmail) || (firstPassValue != secondPassValue) || firstPassValue.Length < 6 || (UserName.Length < 6 || UserName.Length > 30)) { string msgError = ""; if (UserName.Length < 6 || UserName.Length > 30) { msgError += "Потребилеското име трябва да е в границите от 6 до 30 знака."; } if (firstPassValue.Length < 6) { msgError += "Паролата трябва е повече от 6 символа."; } if (Validation.GetHasError(secondPass)) { var errors = Validation.GetErrors(secondPass); msgError += (string)errors[0].ErrorContent; } else if (firstPassValue != secondPassValue) { msgError += "Двете пароли не си съвпадат."; } if (Validation.GetHasError(UEmail)) { var errors = Validation.GetErrors(UEmail); msgError += (string)errors[0].ErrorContent; } WPFMessageBox.MessageBox.ShowError(msgError); return; } PALEntities db = new PALEntities(); var isUsed = db.UserRegistrations.Where(u => u.UserEMail == UserEMailValue).Select(u => u.ID).SingleOrDefault(); if (isUsed == 0) { LogInRegisterCommand.RegisterAndLogInWithValues(db, UserName, firstPassValue, UserEMailValue); } else { WPFMessageBox.MessageBox.ShowError("Вече съществува потребител с същите данни."); } }
private static void CompleteTest() { Pages.TestQuestions.dispatcherTimer.Stop(); int points = ViewModel.CurrentTestPoints; PALEntities dataContext = new PALEntities(); UserGameInformation currentUserGameInformation = GetUserById(dataContext, ID); int currentUserLevel = Convert.ToInt32(currentUserGameInformation.LevelInGame); int currentUserPoints = Convert.ToInt32(currentUserGameInformation.Points) + points; bool levelUp = false; currentUserGameInformation.Points = currentUserPoints.ToString(); if (Convert.ToInt32(currentUserGameInformation.BestScoreFromTests) < points) { currentUserGameInformation.BestScoreFromTests = points.ToString(); } if (currentUserLevel > 2) { int levelSpecialValue = 0; for (int i = 0; i < currentUserLevel; i++) { levelSpecialValue += 30 * i; } if (((currentUserPoints - 100) - levelSpecialValue) / 100 > currentUserLevel) { levelUp = true; currentUserLevel++; currentUserGameInformation.LevelInGame = (currentUserLevel++).ToString(); } } else { if ((currentUserPoints / 100) > currentUserLevel) { levelUp = true; currentUserLevel++; currentUserGameInformation.LevelInGame = (currentUserPoints / 100).ToString(); } } currentUserGameInformation.NumberOfTests = (Convert.ToInt32(currentUserGameInformation.NumberOfTests) + 1).ToString(); dataContext.SaveChanges(); ViewModel.CurrentTestPoints = 0; string msgBoxInfo = string.Format("Честито, вие завършихте успешно избраният от вас тест.\nСпечелени точки: {0}", points); Switcher.Switch(Switcher.StartUpProgramSwitcher, new MainProgram()); WPFMessageBox.MessageBox.ShowInformation(msgBoxInfo); if (levelUp) { string msgBoxLeveUp = string.Format("Честито, вие вдигнахте ниво.\nСега сте {0} ниво", currentUserLevel); WPFMessageBox.MessageBox.ShowInformation(msgBoxLeveUp); } }
private void EdditPicture(object sender, MouseButtonEventArgs e) { OpenFileDialog op = new OpenFileDialog(); op.Title = "Избери изображение"; op.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" + "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" + "Portable Network Graphic (*.png)|*.png"; if (op.ShowDialog() == true) { string url = op.FileName; string uploadedImageURL = UploadImage(url); if (!string.IsNullOrEmpty(uploadedImageURL)) { PALEntities dataContex = new PALEntities(); UserPersonalInformation userPersonalInfo = GetUserById(dataContex, ViewModels.ViewModel.ID); userPersonalInfo.AvatarPicture = uploadedImageURL; dataContex.SaveChanges(); ImageBrush.ImageSource = new BitmapImage(new Uri(uploadedImageURL)); } } }
private UserPersonalInformation GetUserById(PALEntities dataContex, int id) { UserPersonalInformation userPersonalInfo = dataContex.UserPersonalInformations.FirstOrDefault(p => p.UserRegID == id); return(userPersonalInfo); }
public static void RegisterAndLogInWithValues(PALEntities db, string UserName, string Password, string EMail) { RegisterWithValues(db, UserName, Password, EMail); LogInFromRegister(); }