Пример #1
0
        async void GetUser()
        {

            bool state = true;


            Users.Clear();
            HttpClient client = new HttpClient();
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/UserData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParser() { Email = theEmail })));
            message.Headers.Clear();
            message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
            message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");

            try
            {
                HttpResponseMessage response = await client.SendAsync(message);
                string content = await response.Content.ReadAsStringAsync();
                DataToList a = JsonConvert.DeserializeObject<DataToList>(content);
                foreach (var item in a.GetStringList())
                {
                    Users.Add(item);


                }

                if (Users.Count == 0)
                {
                    await DisplayAlert("Problem", " No Doctor in database", "ok");
                }
                else
                {
                    Username.Text = Users[0];
                    Email.Text = Users[1];
                    Password.Text = Users[2];
                    Phonenumber.Text = Users[3];
                }
            }
            catch (Exception e)
            {
                state = false;
            }
            if (state == false)
            {

                await DisplayAlert("Problem", "Issue with connection", "ok");
            }


        }
Пример #2
0
        private async void Registered(object sender, EventArgs args)
        {
            bool state = true;

            try
            {
                if (!(String.IsNullOrEmpty(EntryTitle.Text) || String.IsNullOrEmpty(EntryTitle2.Text) || String.IsNullOrEmpty(EntryTitle3.Text) || String.IsNullOrEmpty(EntryTitle4.Text) || String.IsNullOrEmpty(EntryTitle5.Text)))
                {
                    // here you Create Data
                    HttpClient         client  = new HttpClient();
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, "https://api.parse.com/1/classes/UserData");
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");

                    if (EntryTitle2.Text.Contains("@") && EntryTitle2.Text.Contains(".com"))
                    {
                        if ((EntryTitle3.Text == EntryTitle4.Text) && (EntryTitle3.Text.Length <= 16 && EntryTitle3.Text.Length >= 8))
                        {
                            int value;
                            if (int.TryParse(EntryTitle5.Text, out value) && EntryTitle5.Text.Length == 10)
                            {
                                var                MyList   = new List <string>();
                                HttpClient         client1  = new HttpClient();
                                HttpRequestMessage message1 = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/UserData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParser()
                                {
                                    Email = EntryTitle2.Text
                                })));
                                message1.Headers.Clear();
                                message1.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                                message1.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");


                                HttpResponseMessage response = await client1.SendAsync(message1);

                                string content = await response.Content.ReadAsStringAsync();

                                DataToList a = JsonConvert.DeserializeObject <DataToList>(content);
                                foreach (var item in a.GetStringList())
                                {
                                    MyList.Add(item);
                                }

                                if (a.GetStringList().Contains(EntryTitle2.Text))
                                {
                                    await DisplayAlert("Mistake", "Email already exists", "ok");

                                    return;
                                }


                                string json = JsonConvert.SerializeObject(new DataParser()
                                {
                                    Username = EntryTitle.Text, Email = EntryTitle2.Text, Password = EntryTitle3.Text, PhoneNumber = EntryTitle5.Text
                                });
                                message.Content = new StringContent(json, Encoding.UTF8, "application/json");
                                message.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                                HttpResponseMessage response3 = await client.SendAsync(message);

                                string content3 = await response.Content.ReadAsStringAsync();
                                await DisplayAlert("Congratulations !", " Your Account has been Created", "ok");

                                await Navigation.PopAsync();
                            }
                            else
                            {
                                await DisplayAlert("Problem", "Put a proper Phone Number !", "ok");
                            }
                        }
                        else
                        {
                            await DisplayAlert("Problem", " - check if password is the same \n - must be more 8 and less than 16 characters", "ok");
                        }
                    }
                    else
                    {
                        await DisplayAlert("Problem", "Put a proper Email ! ", "ok");
                    }
                }
                else
                {
                    await DisplayAlert("Problem", "Must Fill all the blanks ! ", "ok");
                }
            }
            catch (Exception e)
            {
                state = false;
            }
            if (state == false)
            {
                await DisplayAlert("Problem", "No internet connection", "ok");
            }
        }
Пример #3
0
        private async void Login(object sender, EventArgs args)
        {
            bool state = true;
            await sign.ScaleTo(0.95, 50, Easing.CubicOut);

            await sign.ScaleTo(1, 50, Easing.CubicIn);

            Cover.IsVisible  = true;
            Cover2.IsVisible = true;

            loading.IsVisible = true;
            try
            {
                if (!(String.IsNullOrEmpty(EntryTitle.Text) || String.IsNullOrEmpty(EntryTitle2.Text)))
                {
                    // here you fetch Data
                    HttpClient client = new HttpClient();
                    client.Timeout = TimeSpan.FromSeconds(10);
                    HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "https://api.parse.com/1/classes/UserData?" + WebUtility.UrlEncode("where=" + JsonConvert.SerializeObject(new DataParser()
                    {
                        Email = EntryTitle.Text, Password = EntryTitle2.Text
                    })));
                    message.Headers.Clear();
                    message.Headers.Add("X-Parse-Application-Id", "2kWwje4PWZ980GmHQBk4EneY7DkENmlikDEZdwKt");
                    message.Headers.Add("X-Parse-REST-API-Key", "3cZnB4kNlPYCChLXEp90tjuBbioTBcycnkMtV9qC");
                    // var Timeout = Convert.ToInt32(TimeSpan.FromMilliseconds(5000));
                    HttpResponseMessage response = await client.SendAsync(message);

                    // await WaitAndExecute(5000);

                    string content = await response.Content.ReadAsStringAsync();

                    DataToList a = JsonConvert.DeserializeObject <DataToList>(content);



                    foreach (var item in a.GetStringList())
                    {
                        MyList.Add(item);
                    }



                    if (a.GetStringList().Contains(EntryTitle.Text))
                    {
                        loading.IsVisible = false;
                        Class1 c = new Class1();
                        c.Master = EntryTitle.Text;
                        await Navigation.PushAsync(new Menu(MyList[0], EntryTitle.Text));

                        //  EntryTitle.Text = "";
                        EntryTitle2.Text = "";
                        Cover.IsVisible  = false;
                        Cover2.IsVisible = false;
                        MyList.Clear();
                    }
                    else
                    {
                        await DisplayAlert("Problem", "Wrong Username or Password!", "ok");

                        loading.IsVisible = false;
                        Cover.IsVisible   = false;
                        Cover2.IsVisible  = false;
                    }
                }
                else
                {
                    await DisplayAlert("Problem", "Fill in the blanks", "ok");

                    loading.IsVisible = false;

                    Cover.IsVisible  = false;
                    Cover2.IsVisible = false;
                }
            }
            catch (Exception e)
            {
                state = false;
            }

            if (state == false)
            {
                Cover2.IsVisible  = false;
                Cover.IsVisible   = false;
                loading.IsVisible = false;
                await DisplayAlert("Problem", "Issue with connection", "ok");
            }
        }