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 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 static UserGameInformation GetUserById(PALEntities dataContex, int id) { UserGameInformation userGameInfo = dataContex.UserGameInformations.FirstOrDefault(p => p.UserRegID == id); return(userGameInfo); }