Esempio n. 1
0
        private async void BConfirm_Click(object sender, EventArgs e)
        {
            //CreateGroup(View.FindViewById<EditText>(Resource.Id.edittextNewGroup).Text);
            string         groupname = View.FindViewById <EditText>(Resource.Id.edittextNewGroup).Text;
            RequestHandler request   = new RequestHandler(Context);

            DB_Singleton db       = DB_Singleton.Instance;
            string       token    = db.Retrieve("Token");
            var          response = await request.CreateGroup(groupname, token);

            int statusCode = (int)response.StatusCode;

            if ((int)response.StatusCode == 200)
            {
                db.AddGroup(groupname, (string)JObject.Parse(response.Content)["groupID"]);
                Success();
            }
            else
            {
                Failure();
            }

            /*
             * AlertDialog.Builder alert = new AlertDialog.Builder(this.Context);
             * alert.SetTitle("Create the new group " + EditTextGroupName.Text + "?");
             *
             * //Send new location information to database
             * alert.SetPositiveButton("Confirm", (senderAlert, args) =>
             * {
             * //                Task create = CreateGroup().Text);
             *  Dismiss();
             * });
             *
             * //Close dialog and cancel add
             * alert.SetNegativeButton("Cancel", (senderAlert, args) =>
             * {});
             *
             * Dialog dialog = alert.Create();
             * dialog.Show();
             */
        }
        private async void UpdateGroups()
        {
            DB_Singleton   db       = DB_Singleton.Instance;
            string         token    = db.Retrieve("Token");
            RequestHandler request  = new RequestHandler(Context);
            IRestResponse  response = await request.PullGroups(token);

            List <UserGroup> userGroupList = ReformatResponse(response.Content);

            foreach (UserGroup user in userGroupList)
            {
                db.AddGroup(user.GroupName, user.GroupID);
            }
            if (userGroupList.Count > 0)
            {
                db.ChangeActiveGroup(userGroupList[0]);
            }
            //CAUTION A NEW USER THAT TRIES TO ACCESS ELEMENTS
            //WITHOUT A GROUP WILL CRASH THE APP
            else
            {
                db.ChangeActiveGroup(new UserGroup(null, null));
            }
        }