// Load the questions private async void LoadModules() { try { // Load the questions WebRequestHelper help = new WebRequestHelper(); string data = await help.getData("http://mbbsweb.azurewebsites.net/api/Survey/GetSurveyQuestions?languageID=EN"); questions = JsonConvert.DeserializeObject <List <Question> >(data); } catch (Exception) { // Display no data found Debug.WriteLine("No data found"); } }
// Login with provided input private async void ButtonLogin_OnClicked(object sender, EventArgs e) { WebRequestHelper help = new WebRequestHelper(); // Check if input is null or empty if (string.IsNullOrEmpty(EmailEntry.Text) || string.IsNullOrEmpty(PasswordEntry.Text)) { // Error message MessageLabel.Text = "Please fill in the email and password"; } else { string uName = EmailEntry.Text; string pWord = PasswordEntry.Text; string url = null; string errorText = null; Data data = new Data(); try { // Try to login url = await help.getData("http://mbbsweb.azurewebsites.net/api/Account/Login?email=" + uName + "&password="******"500")) { errorText = "The server is unavailable, please try again later "; } // Username/password error else { errorText = "Username and/or password incorrect"; } } } // If the url is not empty if (!string.IsNullOrEmpty(url)) { // Create the token data.token = url; data.token = data.token.TrimEnd('"'); data.token = data.token.TrimStart('"'); data.LoginName = EmailEntry.Text; Debug.WriteLine((errorText)); // Change the mainpage in the module home page with token (logged in) Application.Current.MainPage = new NavigationPage(new HomePage(data.token)) { BarBackgroundColor = Color.FromHex("#003788") }; } else { // Error message MessageLabel.Text = errorText; } } }