Exemple #1
0
        public async Task<User> Signin(Login login) 
        {
            HttpStringContent postContent = new HttpStringContent(JsonConvert.SerializeObject(login));
            postContent.Headers["Content-Type"] = "application/json";

            try 
            { 
                HttpResponseMessage response = await client.PostAsync(new Uri(serviceUrl, "/api/v1/users/login"), postContent);

                if (response.IsSuccessStatusCode) 
                { 
                    string content = await response.Content.ReadAsStringAsync();
                    User user = JsonConvert.DeserializeObject<User>(content);

                    return user;
                }
            }
            catch
            {
                
            }

            return null;
        }
Exemple #2
0
        private async void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            WaitIndicator.IsVisible = true;

            Login login = new Login();
            login.CountryCode = CountryCodeField.Text;
            login.PhoneNumber = PhoneNumberField.Text;

            User user = await restService.Signin(login);

            WaitIndicator.IsVisible = false;

            if (user != null)
            {
                Messenger.Default.Send(user, Constants.ChatManagerStartChatSession);

                model.Session.User = user;
                model.Session.SaveData();

                NavigationService.Navigate(new Uri("/View/MainPage.xaml", UriKind.RelativeOrAbsolute));
            }
            else
            {
                Registration registration = new Registration();
                registration.CountryCode = CountryCodeField.Text;
                registration.PhoneNumber = PhoneNumberField.Text;

                PhoneApplicationService.Current.State[Constants.Registration] = registration;

                NavigationService.Navigate(new Uri("/View/RegistrationPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }