示例#1
0
        //request thread
        private void RequestLoginInformation()
        {
            // request params
            string        apiUrl          = Settings.apiUrl;
            string        apiMethod       = "loginUser";
            Login_Request myLogin_Request = new Login_Request()
            {
                username = _login_username.Text,
                password = _login_password.Text
            };

            // make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(myLogin_Request) }
            });

            // decode json string to dto object
            API_Response r =
                JsonConvert.DeserializeObject <API_Response>(response);

            // check response
            if (!r.IsError && r.ResponseData == "SUCCESS")
            {
                StartActivity(typeof(MainActivity));
            }
            else
            {
                Toast.MakeText(this, r.ErrorMessage, ToastLength.Long).Show();
            }

            _progressbar.Visibility = ViewStates.Invisible;
        }
示例#2
0
        private void SignUpDialog__onSignUpComplete(object sender, OnSignUpEventArgs e)
        {
            _progressbar.Visibility = ViewStates.Visible;

            // request params
            string           apiUrl             = Settings.apiUrl;
            string           apiMethod          = "registerUser";
            Register_Request myRegister_Request = new Register_Request()
            {
                username = e.Username,
                password = e.Password,
                email    = e.Email
            };

            // make http post request
            string response = Http.Post(apiUrl, new NameValueCollection()
            {
                { "api_method", apiMethod },
                { "api_data", JsonConvert.SerializeObject(myRegister_Request) }
            });

            // decode json string to dto object
            API_Response r =
                JsonConvert.DeserializeObject <API_Response>(response);

            // check response
            if (!r.IsError && r.ResponseData == "SUCCESS")
            {
                _login_username.Text = e.Username;
                _login_password.Text = e.Password;
                Toast.MakeText(this, r.ErrorMessage, ToastLength.Long).Show();
            }
            else
            {
                Toast.MakeText(this, r.ErrorMessage, ToastLength.Long).Show();
            }

            _progressbar.Visibility = ViewStates.Invisible;
        }