Exemplo n.º 1
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtUser.Text) || String.IsNullOrWhiteSpace(txtState.Text) || String.IsNullOrWhiteSpace(txtCountry.Text) ||
                String.IsNullOrWhiteSpace(txtCity.Text) || String.IsNullOrWhiteSpace(txtAge.Text) || String.IsNullOrWhiteSpace(txtPass.Password))
            {
                MessageBox.Show("Please enter valid info.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            User user = new User()
            {
                Username = txtUser.Text,
                Age      = UInt32.Parse(txtAge.Text),
                Location = String.Join(",", txtCity.Text, txtState.Text, txtCountry.Text),
                IsAdmin  = chkIsAdmin.IsChecked ?? false
            };

            Response.BaseResponse success = new Response.BaseResponse()
            {
                Success = true
            };

            FullBookVoteWindow fullBookVoteWindow = new FullBookVoteWindow(userVotes);

            if (userVotes.Count < 10)
            {
                fullBookVoteWindow.ShowDialog();
            }

            if (fullBookVoteWindow.DialogResult == true || userVotes.Count >= 10)
            {
                var register = SqlHandler.AddUser(user, txtPass.Password);
                if (register.Success)
                {
                    foreach (var item in userVotes)
                    {
                        SqlHandler.AddVote(register.Content.ToString(), item.Content.ISBN, item.Rating);
                    }
                }
                else
                {
                    success.Success   = false;
                    success.ErrorText = register.ErrorText;
                }
            }
            else
            {
                success.Success   = false;
                success.ErrorText = "Voting cancelled by user.";
            }

            if (success.Success)
            {
                MessageBox.Show("User has been added successfully", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
                this.Close();
            }
            else
            {
                MessageBox.Show("There was an error while registering!\n\n" + success.ErrorText, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private void btnApplyVote_Click(object sender, RoutedEventArgs e)
 {
     Response.BaseResponse response;
     if (PreviousVote == Vote)
     {
         return;
     }
     if (PreviousVote == -1)
     {
         response = SqlHandler.AddVote(CommonLibrary.LoggedInUser.UserID.ToString(), Book.ISBN, Vote);
     }
     else
     {
         response = SqlHandler.UpdateVote(CommonLibrary.LoggedInUser.UserID.ToString(), Book.ISBN, Vote);
     }
     if (response.Success)
     {
         MessageBox.Show("Successfully added the vote.", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
     }
     else
     {
         MessageBox.Show("Unknown error occured while adding the vote.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }