private async void checkEmail() { try { var httpClient = new HttpClient(); var recentChatPage = new Views.Chat.RecentChatPage(); var payload = "{\"email\": \"" + this.Email + "\"" + "}"; var url = new Uri(App.BaseApiUrl + "/users/search"); HttpContent c = new StringContent(payload, Encoding.UTF8, "application/json"); HttpResponseMessage result = await httpClient.PostAsync(url, c); var users = JsonConvert.DeserializeObject <List <RestUserModel> >(result.Content.ReadAsStringAsync().Result); if (users.Count == 1) { addChat(users[0].Id.ToString()); await Application.Current.MainPage.Navigation.PopAsync(); } else { var toastConfig = new ToastConfig("Email is invalid!"); toastConfig.SetDuration(3000); toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(242, 76, 101)); UserDialogs.Instance.Toast(toastConfig); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } }
private async void checkCreds() { try { var httpClient = new HttpClient(); var payload = "{\"email\": \"" + this.Email + "\"," + "\"password\": \"" + this.password + "\"" + "}"; var url = new Uri(App.BaseApiUrl + "/users/login"); HttpContent c = new StringContent(payload, Encoding.UTF8, "application/json"); HttpResponseMessage result = await httpClient.PostAsync(url, c); System.Diagnostics.Debug.WriteLine(result.Content.ReadAsStringAsync().Result); var users = JsonConvert.DeserializeObject <List <RestUserModel> >(result.Content.ReadAsStringAsync().Result); loading = false; if (users.Count == 1) { Application.Current.Properties["userEmail"] = users[0].Email; Application.Current.Properties["userID"] = users[0].Id; Application.Current.Properties["userImage"] = users[0].Image; Application.Current.Properties["userFullName"] = users[0].FirstName + " " + users[0].LastName; Application.Current.Properties["userPhone"] = users[0].Phone; await Application.Current.SavePropertiesAsync(); await Task.Delay(2000); var recentChatPage = new Views.Chat.RecentChatPage(); await Application.Current.MainPage.Navigation.PushAsync(recentChatPage); } else { var toastConfig = new ToastConfig("Email or Password is invalid!"); toastConfig.SetDuration(3000); toastConfig.SetBackgroundColor(System.Drawing.Color.FromArgb(242, 76, 101)); UserDialogs.Instance.Toast(toastConfig); } } catch (Exception e) { loading = false; System.Diagnostics.Debug.WriteLine("E: " + e); } }