private void btnCreateUser_ClickAsync(object sender, RoutedEventArgs e) { //if the password confirmation is OK if (checkIfPasswordAlike()) { string userName = this.txtBoxUserName.Text; //Start process by asking the backend if the username already exists. CommunicationElements comElements = new CommunicationElements(); // make the Http request and recieve the reponse. var response = comElements.get("User", "UserName="******""); // if username already exists if (response.StatusCode == System.Net.HttpStatusCode.Found) { //give message to user and make him try again with another username. this.txtBoxUserName.Text = ""; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show("Username is already in use. Try another username", "Username already in use", buttons, MessageBoxIcon.Warning); this.txtBoxUserName.Focus(); } else { //If username is not in use create a new UserDTO object UserDTO user = new UserDTO(); user.FirstName = this.txtBoxFirstName.Text; user.MiddleName = this.txtBoxMiddleName.Text; user.LastName = this.txtBoxLastName.Text; user.UserName = this.txtBoxUserName.Text; user.Password = this.pswBoxPassword.Password.ToString(); user.Date = DateTime.Now; response = comElements.post("User", user); if (response.StatusCode == HttpStatusCode.Created) { MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show("User Created", "User Created", buttons); //Change to login window using MainWindowState singleton //Change menustate using MainWindowState singleton NavigationService.Navigate(null); MainWindowState.Instance.changePageInFrame(new Login()); MainWindowState.Instance.changeMenuState("login"); } else { MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show("User not Created", "Database Incident", buttons); } } } }