Exemplo n.º 1
0
        private static void Main()
        {
            var city = SelectCity();

            var storage   = new NativeStorageProvider();
            var authToken = storage.AuthToken;

            if (string.IsNullOrEmpty(authToken))
            {
                var credentialsProvider = new ConsoleCredentialsProvider();
                var loginRequest        = new LoginRequest(credentialsProvider.Login, credentialsProvider.Password);
                var response            = ImaxApi.Login(loginRequest).Result;
                if (response.Succeeded)
                {
                    authToken = storage.AuthToken = response.Token;
                }
                else
                {
                    return;
                }
            }

            var profileRequest  = new ProfileRequest(authToken);
            var profileResponse = ImaxApi.Profile(profileRequest).Result;

            var registerRequest  = new RegisterRequest(new CustomerName("Vasya", null, "Pupkin"), Gender.Male, new DateTime(2012, 12, 21), PhoneNumber.Parse("+380123456789"), "*****@*****.**", "qwerty");
            var registerResponse = ImaxApi.Register(registerRequest).Result;
        }
Exemplo n.º 2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                var authToken       = (string)ApplicationData.Current.LocalSettings.Values["AuthToken"];
                var profileRequest  = new ProfileRequest(authToken);
                var profileResponse = await ImaxApi.Profile(profileRequest);

                CustomerNameBlock.Text = profileResponse.CustomerName.FullName;
                CustomerIdBlock.Text   = profileResponse.UserId;
                CardNumberBlock.Text   = Ean13Generator.GenerateBarCode(profileResponse.CustomerCard);
                BonusesBlock.Text      = profileResponse.Bonuses;
            }
        }
Exemplo n.º 3
0
        private async void Login()
        {
            LoginButton.IsEnabled = false;

            var registerRequest = new LoginRequest(LoginBox.Text, PasswordBox.Password);
            var response        = await ImaxApi.Login(registerRequest);

            if (response.Succeeded)
            {
                ApplicationData.Current.LocalSettings.Values.Add("AuthToken", response.Token);
                Frame.Navigate(typeof(ProfilePage));
            }
            else
            {
                await new MessageDialog("Sorry, an error occured.").ShowAsync();
                LoginButton.IsEnabled = true;
            }
        }
Exemplo n.º 4
0
        private async void Register()
        {
            RegisterButton.IsEnabled = false;

            var name            = new CustomerName(NameBox.Text, SurnameBox.Text);
            var gender          = MaleGenderBox.IsChecked.GetValueOrDefault() ? Gender.Male : Gender.Female;
            var countryCode     = CountryCodeBox.SelectedIndex == 0 ? "+38" : "+375";
            var phoneNumber     = PhoneNumber.Parse($"{countryCode}{PhoneNumberBox.Text}");
            var registerRequest = new RegisterRequest(name, gender, BirthdatePicker.Date.Date, phoneNumber, EmailBox.Text, PasswordBox.Password);
            var response        = await ImaxApi.Register(registerRequest);

            if (response.Succeeded)
            {
                await new MessageDialog("Done").ShowAsync();
            }
            else
            {
                await new MessageDialog("Failed").ShowAsync();
            }

            RegisterButton.IsEnabled = true;
        }
Exemplo n.º 5
0
        private static City SelectCity()
        {
            System.Console.Clear();
            var cities = ImaxApi.GetCities().Result.Cities;

            for (int i = 0; i < cities.Length; i++)
            {
                System.Console.WriteLine($"{i}. {cities[i].Name}");
            }
            System.Console.WriteLine("Enter city number...");
            while (true)
            {
                int number;
                if (int.TryParse(System.Console.ReadLine(), out number))
                {
                    if (number >= 0 && number < cities.Length)
                    {
                        return(cities[number]);
                    }
                }
            }
        }