private async void Sign_in_ClickAsync(object sender, RoutedEventArgs e) { // Take username and password and compare against azure database to validate the user var uName = usernameTxt.Text.ToString(); var uPass = passwordBox.Password; userCollection = await azureUsersTable.ToCollectionAsync(); var check = userCollection.FirstOrDefault(u => u.Username.Equals(uName) && u.Password.Equals(uPass)); if (check == null) { var confirmation = new MessageDialog("Wrong username or password! Please try again."); confirmation.Title = "Wrong Input!"; confirmation.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); var choice = await confirmation.ShowAsync(); } else { UniqueUser.UniqueID = check.ID.ToString(); //var confirmation = new MessageDialog("Match!" + ", " + UniqueUser.UniqueID + ", " + check.Username.ToString() + ", "); //confirmation.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); //var choice = await confirmation.ShowAsync(); Frame.Navigate(typeof(MainPage)); } }
private async Task UsernameValidation() { var uName = usernameTxt.Text; userCollection = await azureUsersTable.ToCollectionAsync(); var check = userCollection.FirstOrDefault(u => u.Username.Equals(uName)); if (check == null) { check = userCollection.FirstOrDefault(); } try { if (check.Username.ToString().Equals(uName)) { var confirmation = new MessageDialog("Username '" + uName + "' is already in use! Please choose another username."); confirmation.Title = "Wrong Input!"; confirmation.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); var choice = await confirmation.ShowAsync(); usernameTxt.BorderBrush = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red); } else { // Declare DOB variable & collect relative selected box items var dob = dobDay.SelectionBoxItem + "/" + dobMonth.SelectionBoxItem + "/" + dobYear.SelectionBoxItem; // Upload data to Azure Cloud Database table await UploadAsync(nameTxt.Text, surnameTxt.Text, dob, usernameTxt.Text, passwordBox.Password); // Message box to thank for registration InformationMessage(errorMessage4, errorTitle4); Frame.Navigate(typeof(LoginPage)); } } catch (Exception e) { var confirmation = new MessageDialog("Unexpected Error!'" + check.Username.ToString()); confirmation.Title = "Error!"; confirmation.Commands.Add(new UICommand { Label = "Ok", Id = 0 }); var choice = await confirmation.ShowAsync(); } }
private async Task RefreshTodoItems() { MobileServiceInvalidOperationException exception = null; try { items = await parameters.ToCollectionAsync(); stats = await statistics.OrderBy <DateTime>(item => item.ValueDateTime).ToCollectionAsync(); } catch (MobileServiceInvalidOperationException e) { exception = e; } catch (HttpRequestException e) { await new MessageDialog(String.Format("{0}\nService is not available", e.Message), "Error loading items").ShowAsync(); return; } if (exception != null) { await new MessageDialog(exception.Message, "Error loading items").ShowAsync(); } else { currentHouseEntity.HouseEntity.Temperature = items.FirstOrDefault(i => i.Name == "Temperature")?.Value; currentHouseEntity.HouseEntity.Humidity = items.FirstOrDefault(i => i.Name == "Humidity")?.Value; currentHouseEntity.HouseEntity.FanMode = items.FirstOrDefault(i => i.Name == "FanMode").Value; currentHouseEntity.HouseEntity.FanPower = items.FirstOrDefault(i => i.Name == "FanPower").Value; currentHouseEntity.HouseEntity.Door = items.FirstOrDefault(i => i.Name == "Door").Value; //List<StatisticsHTs> list = new List<StatisticsHTs>() //{ // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,0,0), Humidity = 80, Temperature = 24}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,2,0), Humidity = 82, Temperature = 24}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,4,0), Humidity = 90, Temperature = 25}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,6,0), Humidity = 99, Temperature = 25}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,8,0), Humidity = 99, Temperature = 25}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,10,0), Humidity = 91, Temperature = 26}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,12,0), Humidity = 77, Temperature = 26}, // new StatisticsHTs() {ValueDateTime = new DateTime(2017,12,20,12,14,0), Humidity = 64, Temperature = 24} //}; currentHouseEntity.Statistics = stats.ToList(); } }
private async void EndMatchButton_Click(object sender, RoutedEventArgs e) { if (ConvertStringToInt(TeamOneScoreTextBlock.Text) != ConvertStringToInt(TeamTwoScoreTextBlock.Text)) { if (ConvertStringToInt(TeamOneScoreTextBlock.Text) > ConvertStringToInt(TeamTwoScoreTextBlock.Text)) { tournamentTeams = await tournamentTeamsTable.Where(p => p.TeamId == TeamOneIdTextBlock.Text && p.TournamentId == TournamentIdTextBlock.Text) .ToCollectionAsync(); TournamentTeam tournamentTeam = tournamentTeams.FirstOrDefault(); tournamentTeam.TeamWins = tournamentTeam.TeamWins + 1; await tournamentTeamsTable.UpdateAsync(tournamentTeam); } else if (ConvertStringToInt(TeamOneScoreTextBlock.Text) < ConvertStringToInt(TeamTwoScoreTextBlock.Text)) { tournamentTeams = await tournamentTeamsTable.Where(p => p.TeamId == TeamTwoIdTextBlock.Text && p.TournamentId == TournamentIdTextBlock.Text) .ToCollectionAsync(); TournamentTeam tournamentTeam = tournamentTeams.FirstOrDefault(); tournamentTeam.TeamWins = tournamentTeam.TeamWins + 1; await tournamentTeamsTable.UpdateAsync(tournamentTeam); } tournamentTeams = await tournamentTeamsTable.Where(p => p.TeamId == TeamOneIdTextBlock.Text && p.TournamentId == TournamentIdTextBlock.Text) .ToCollectionAsync(); TournamentTeam tournamentTeamOne = tournamentTeams.FirstOrDefault(); tournamentTeamOne.TeamPoints = tournamentTeamOne.TeamPoints + ConvertStringToInt(TeamOneScoreTextBlock.Text); await tournamentTeamsTable.UpdateAsync(tournamentTeamOne); tournamentTeams = await tournamentTeamsTable.Where(p => p.TeamId == TeamTwoIdTextBlock.Text && p.TournamentId == TournamentIdTextBlock.Text) .ToCollectionAsync(); TournamentTeam tournamentTeamTwo = tournamentTeams.FirstOrDefault(); tournamentTeamTwo.TeamPoints = tournamentTeamTwo.TeamPoints + ConvertStringToInt(TeamTwoScoreTextBlock.Text); await tournamentTeamsTable.UpdateAsync(tournamentTeamTwo); matches = await matchesTable.Where(p => p.Id == MatchIdTextBlock.Text).ToCollectionAsync(); Game match = matches.First(); match.Ended = true; await matchesTable.UpdateAsync(match); EndMatchButton.IsEnabled = false; } else { await new MessageDialog("Nie może być remisu").ShowAsync(); } }
private async void signUpBtn_Click(object sender, RoutedEventArgs e) { Admin admin = new Admin(); admin.Username = email.Text; admin.Password = password.Password; MobileServiceCollection <Admin, Admin> items = await App.MobileService.GetTable <Admin>().Where(a => a.Username == admin.Username).ToCollectionAsync(); admin = items.FirstOrDefault(a => a.Username == admin.Username); if (admin != null) { ContentDialog dialog = new ContentDialog() { Title = "Failed", Content = "Username already taken", PrimaryButtonText = "OK" }; await dialog.ShowAsync(); } else { admin = new Admin(); admin.Username = email.Text; admin.Password = password.Password; await App.MobileService.GetTable <Admin>().InsertAsync(admin); ContentDialog confirmDialog = new ContentDialog() { Title = "Success", Content = "Registration Success", PrimaryButtonText = "OK" }; var result = await confirmDialog.ShowAsync(); if (result == ContentDialogResult.Primary) { this.Frame.GoBack(); } } }
private async void Button_Click(object sender, RoutedEventArgs e) { progressRing.IsActive = true; MobileServiceCollection <Admin, Admin> items = await App.MobileService.GetTable <Admin>() .Where(a => a.Username == username.Text && a.Password == password.Password).ToCollectionAsync(); Admin admin = items.FirstOrDefault(a => a.Username == username.Text && a.Password == password.Password); if (admin != null) { App.Admin = admin; (Window.Current.Content as Frame).Navigate(typeof(ManagePage), admin); } else { var dialog = new MessageDialog("Invalid username and password"); username.Text = ""; password.Password = ""; await dialog.ShowAsync(); } progressRing.IsActive = false; }
private async void changePassBtn_Click(object sender, RoutedEventArgs e) { try { if (currentPass.Password == App.Admin.Password && username.Text == App.Admin.Username && newPass.Password != string.Empty) { App.Admin.Password = newPass.Password; await App.MobileService.GetTable <Admin>().UpdateAsync(App.Admin); ContentDialog confirmDialog = new ContentDialog() { Title = "Success", Content = "Password has been changed", PrimaryButtonText = "Sign out" }; await confirmDialog.ShowAsync(); (Window.Current.Content as Frame).Navigate(typeof(MainPage)); } else { ContentDialog confirmDialog = new ContentDialog() { Title = "Failed", Content = "Incorrect username and password", PrimaryButtonText = "Ok" }; await confirmDialog.ShowAsync(); } } catch { MobileServiceCollection <Admin, Admin> items = await App.MobileService.GetTable <Admin>().Where(a => a.Username == username.Text).ToCollectionAsync(); App.Admin = items.FirstOrDefault(); if ((App.Admin != null) && newPass.Password != string.Empty) { App.Admin.Password = newPass.Password; await App.MobileService.GetTable <Admin>().UpdateAsync(App.Admin); ContentDialog confirmDialog = new ContentDialog() { Title = "Success", Content = "Password has been changed", PrimaryButtonText = "Ok" }; await confirmDialog.ShowAsync(); (Window.Current.Content as Frame).Navigate(typeof(MainPage)); } else { ContentDialog confirmDialog = new ContentDialog() { Title = "Failed", Content = "Incorrect username", PrimaryButtonText = "Ok" }; await confirmDialog.ShowAsync(); } } }