Example #1
0
        private void SILIP_Click(object sender, EventArgs e)
        {
            // Sign in click events \\
            Family      db      = new Family();
            RestHandler objRest = new RestHandler();

            // Username or password empty \\
            if (UNLIP.Text == "")
            {
                Toast.MakeText(this, "Please enter your family name", ToastLength.Short).Show();
                return;
            }
            if (PLIP.Text == "")
            {
                Toast.MakeText(this, "Please enter the password", ToastLength.Short).Show();
                return;
            }

            var families = objRest.ExecuteGetRequestF();

            // Check username and password is correct \\
            int index = families.FindIndex(f => f.FamilyName == UNLIP.Text && f.UserPassword == PLIP.Text);

            // If correct logs you in and opens main page \\
            if (index >= 0)
            {
                Intent nextActivity = new Intent(this, typeof(MainPage));

                int tempid = families.Find(p => p.FamilyName == UNLIP.Text).FamilyID;

                // Stores FamilyID and FamilyName in singleton class \\
                FamilySingleton f = FamilySingleton.Instance;
                f.FamilyID   = tempid;
                f.FamilyName = UNLIP.Text;

                // Starts main page activity \\
                StartActivity(nextActivity);
            }
            else
            {
                // If incorrect tost message for user to reaslise they got something wrong \\
                Toast.MakeText(this, "Wrong family name or password sorry" +
                               "\n Please try again", ToastLength.Short).Show();
                return;
            }
        }
        private void CreateFamilyCre_Click(object sender, EventArgs e)
        {
            RestHandler objRest  = new RestHandler();
            var         families = objRest.ExecuteGetRequestF();

            // Check is texts boxes are empty \\
            if (FamilyNameCre.Text == "")
            {
                Toast.MakeText(this, "Please enter Family Name", ToastLength.Short).Show();
                return;
            }
            if (PasswordCre.Text == "")
            {
                Toast.MakeText(this, "Please enter a Password", ToastLength.Short).Show();
                return;
            }

            int index = families.FindIndex(f => f.FamilyName == FamilyNameCre.Text);

            // Check if Family name is already taken \\
            if (index >= 0)
            {
                Toast.MakeText(this, "This name is taken" +
                               "\n       Please try again", ToastLength.Short).Show();
                return;
            }
            else
            {
                // Add a new family and post it the online database \\
                Family f = new Family();

                f.FamilyName   = FamilyNameCre.Text;
                f.UserPassword = PasswordCre.Text;

                objRest.ExecutePostRequestF(f);

                // Toast message for user to know its worked \\
                Toast.MakeText(this, FamilyNameCre.Text + " family created", ToastLength.Short).Show();
                return;
            }
        }