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());
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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));
                }
            }
        }