public MainInfoWindow() { InitializeComponent(); //Getting the data for the GameListBox List <GameDTO> gamesDTOList; var response = comElements.get("Game", "", ""); if (response.StatusCode == HttpStatusCode.OK) { //Populating the GameListBox ObservableCollection <GameView> gameListView = new ObservableCollection <GameView>(); GamesListBox.ItemsSource = gameListView; var content = response.Content.ReadAsStringAsync(); gamesDTOList = JsonConvert.DeserializeObject <List <GameDTO> >(content.Result); if (gamesDTOList != null) { foreach (GameDTO game in gamesDTOList) { gameListView.Add(new GameView() { Id = game.Id, Name = game.Name, Company = game.Company, Revision = game.Revision }); } } else { //Messagebox no games. } } }
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); } } } }
protected void Login_ClickAsync(object sender, RoutedEventArgs args) { //Getting a response from server with the Login credentials var response = comElements.get("Login", "UserName="******"&Password="******""); if (response.StatusCode == HttpStatusCode.OK) { //removing escape character from result. string result = response.Content.ReadAsStringAsync().Result.Replace("\"", ""); //store token in SettingsAndData singleton for futher use. SettingsAndData.Instance.token = result; //Remove Login page from memory NavigationService.Navigate(null); //Change to MainInfoWindow window using MainWindowState singleton //Change menustate using MainWindowState singleton MainWindowState.Instance.changePageInFrame(new MainInfoWindow()); MainWindowState.Instance.changeMenuState("loggedon"); } else { if (response.StatusCode == HttpStatusCode.NoContent) { //If user does not exist ask if user wants to create new user. MessageBoxButtons buttons = MessageBoxButtons.YesNo; DialogResult diagResult = MessageBox.Show("User not found. Do you want to create a new user", "User not found", buttons, MessageBoxIcon.Warning); if (diagResult == DialogResult.Yes) { MainWindowState.Instance.changePageInFrame(new CreateUser()); MainWindowState.Instance.changeMenuState("createuser"); } } //If username is already used. if (response.StatusCode == HttpStatusCode.Forbidden) { MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show("Password is wrong. Try again", "Password wrong", buttons, MessageBoxIcon.Warning); this.passwordBox.Focus(); } } }