private async void btnClaimITAS_Clicked(object sender, EventArgs e) { var client = new WebApi(); var rewardName = _list.Where(x => x.RewardName.Contains("ITAS")).Select(x => x.RewardName).FirstOrDefault(); var checkUserClaim = await client.Post($"Rewards/CheckAvailableRewards?rewardName={rewardName}&userID={_user.userID}", ""); if (checkUserClaim == "\"No available rewards for this user at the moment!\"") { var newRewardJson = await client.Post($"Rewards/GetNewReward?rewardName={rewardName}&userID={_user.userID}", ""); if (newRewardJson == "\"Unable to claim as there are no more available rewards!\"") { await DisplayAlert("Rewards", $"There are no more {rewardName} vouchers left!", "Ok"); } else if (newRewardJson == "\"Unable to claim reward! Insufficient points!\"") { await DisplayAlert("Rewards", "Unable to claim reward! Insufficient points!", "Ok"); } else { var newReward = JsonConvert.DeserializeObject <Reward>(newRewardJson); var newClaim = new UserClaim() { isClaimed = false, rewardsIDFK = newReward.ID, userIDFK = _user.userID }; var JsonData = JsonConvert.SerializeObject(newClaim); var response = await client.Post("UserClaims/Create", JsonData); if (response == "\"Claim is online!\"") { var userClaimJson = await client.Post($"UserClaims/GetClaim?rewardID={newReward.ID}", ""); var userClaim = JsonConvert.DeserializeObject <UserClaim>(userClaimJson); await DisplayAlert("Rewards", "Reward claimed successfully! Please use within 3 minutes!", "Ok"); await Navigation.PushAsync(new RewardsClaim(newReward, userClaim)); } else { await DisplayAlert("Rewards", "Something went wrong. Please contact our administrator to ensure the voucher you claimed is given to you!", "Ok"); } } } else { var reward = JsonConvert.DeserializeObject <Reward>(checkUserClaim); await DisplayAlert("Rewards", "Reward claimed successfully! Please use within 3 minutes!", "Ok"); var userClaimJson = await client.Post($"UserClaims/GetClaim?rewardID={reward.ID}", ""); var userClaim = JsonConvert.DeserializeObject <UserClaim>(userClaimJson); await Navigation.PushAsync(new RewardsClaim(reward, userClaim)); } }
private async void btnLogin_Clicked(object sender, EventArgs e) { if (entryUserID.Text == null || entryPassword.Text == null || entryUserID.Text == "" || entryPassword.Text == "") { await DisplayAlert("Login", "Please check your fields! One or both of the fields are empty!", "Ok"); } else { var client = new WebApi(); var response = await client.Post($"Users/Login?userID={entryUserID.Text}&password={entryPassword.Text}", ""); if (response == "\"User account does not exist!\"") { await DisplayAlert("Login", "User account does not exist!", "Ok"); } else if (response == "\"Password is incorrect! Please try again!\"") { await DisplayAlert("Login", "Password is incorrect! Please try again!", "Ok"); } else { var userData = JsonConvert.DeserializeObject <User>(response); await DisplayAlert("Login", $"Welcome {userData.userName}!", "Ok"); await Navigation.PushAsync(new MainMenu(userData)); } } }
private async Task RefreshUser() { var client = new WebApi(); var response = await client.Post($"Users/GetSpecificUser?userID={_user.userID}", ""); _user = JsonConvert.DeserializeObject <User>(response); }
private async Task GetQuestions() { var client = new WebApi(); var response = await client.Post($"Questions/GetCategoryQuestions?category=TP", ""); _questionSet = JsonConvert.DeserializeObject <List <Question> >(response); numberOfQuestion = _questionSet.Count(); PopulateQuestion(); }
private async Task LoadPoints() { var client = new WebApi(); var response = await client.Post("Rewards/GetRequiredPoints", ""); _list = JsonConvert.DeserializeObject <List <RequiredPoint> >(response); foreach (var item in _list) { if (item.RewardName.Contains("ITAS")) { lblITASPoint.Text = item.RequiredPoints.ToString(); } else if (item.RewardName.Contains("DesPad")) { lblDesPoint.Text = item.RequiredPoints.ToString(); } } }
private async Task CheckQuizzes() { var client = new WebApi(); var response = await client.Post($"Questions/CheckCategory?userID={_user.userID}", ""); var questionTaken = JsonConvert.DeserializeObject <List <string> >(response); foreach (var item in questionTaken) { if (item == "Course") { btnCourses.IsVisible = false; } else if (item == "TP") { btnTP.IsVisible = false; } } if (btnCourses.IsVisible == false && btnTP.IsVisible == false) { lblCompleted.IsVisible = true; } }
private async void btnCreate_Clicked(object sender, EventArgs e) { if (entryName.Text == null || entryUserID.Text == null || entryPassword == null || entryRePassword == null) { await DisplayAlert("Create Account", "One of more field(s) are empty!", "Ok"); } else if (entryPassword.Text != entryRePassword.Text) { await DisplayAlert("Create Account", "Your passwords do not match! Please check and try again!", "Ok"); } else { var newUser = new User() { userName = entryName.Text, userID = entryUserID.Text, password = entryPassword.Text, points = 0 }; var client = new WebApi(); var JsonData = JsonConvert.SerializeObject(newUser); var response = await client.Post("Users/Create", JsonData); if (response == "\"User ID has been used!\"") { await DisplayAlert("Create Account", "User ID has been used!", "Ok"); } else if (response == "\"Unable to create user account! Please contact our administrator!\"") { await DisplayAlert("Create Account", "Unable to create user account! Please contact our administrator!", "Ok"); } else { await DisplayAlert("Create Account", "Account created successfully!", "Ok"); await Navigation.PopAsync(); } } }
private async Task LoadEvents() { var client = new WebApi(); var response = await client.Post("Events", ""); _event = JsonConvert.DeserializeObject <List <Event> >(response); numberOfDays = (from x in _event group x by x.eventTime.Date into y select y.Key).Count(); _customViewIndex = (from x in _event group x by x.eventTime.Date into y select y.Key).ToList(); var currentDay = _customViewIndex.ElementAt(dayIndex).Date; var customView = (from x in _event where x.eventTime.Date == currentDay select new { eventName = x.eventName, eventVenue = x.eventVenue, eventTime = x.eventTime.ToLocalTime().ToString("HH:mm") }).ToList(); lvEvent.ItemsSource = customView; var dayString = currentDay.ToString("dd/MM/yyyy"); lblDay.Text = $"Event of {dayString}"; }
private async void btnSubmit_Clicked(object sender, EventArgs e) { var client = new WebApi(); var userResponse = new UserResponse() { userIDFK = _user.userID, questionIDFK = _questionSet[questionIndex].ID }; if (rbAnswerOne.IsChecked) { userResponse.userAnswer = lblAnswerOne.Text; } else if (rbAnswerTwo.IsChecked) { userResponse.userAnswer = lblAnswerTwo.Text; } else if (rbAnswerThree.IsChecked) { userResponse.userAnswer = lblAnswerThree.Text; } else if (rbAnswerFour.IsChecked) { userResponse.userAnswer = lblAnswerFour.Text; } if (userResponse.userAnswer == _questionSet[questionIndex].Correct) { userResponse.isCorrect = true; } else { userResponse.isCorrect = false; } var JsonData = JsonConvert.SerializeObject(userResponse); var response = await client.Post("UserResponses/Create", JsonData); if (response == "\"Congrats! Your answer was correct!\"") { await DisplayAlert("Feedback", "Congrats! Your answer was correct!", "Ok"); if (questionIndex == numberOfQuestion - 1) { await DisplayAlert("End of quiz", "You have completed the last question! Redirecting you back to Quiz Menu!", "Ok"); await Navigation.PopAsync(); } else { questionIndex += 1; ClearSelections(); PopulateQuestion(); } } else if (response == "\"Your answer is incorrect!\"") { await DisplayAlert("Feedback", $"Your answer is incorrect! The correct answer is: {_questionSet[questionIndex].Correct}", "Ok"); if (questionIndex == numberOfQuestion - 1) { await DisplayAlert("End of quiz", "You have completed the last question! Redirecting you back to Quiz Menu!", "Ok"); await Navigation.PopAsync(); } else { questionIndex += 1; ClearSelections(); PopulateQuestion(); } } else if (response == "\"Unable to submit response!Please try again later!\"") { await DisplayAlert("Feedback", "Unable to submit response! Please try again later!", "Ok"); await Navigation.PopAsync(); } }