예제 #1
0
        /// <summary>
        /// PostRegistrationDetails
        /// </summary>
        /// <param name="url"></param>
        /// <param name="req"></param>
        /// <returns></returns>
        protected HttpStatusCode PostRegistrationDetails(string url, RegistrationRequest req)
        {
            string serializedObj = JsonConvert.SerializeObject(req);
            byte[] buf = Encoding.UTF8.GetBytes(serializedObj);

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
            request.ContentType = "application/json";
            request.Method = "POST";
            request.GetRequestStream().Write(buf, 0, buf.Length);

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                return response.StatusCode;
            }
        }
예제 #2
0
        /// <summary>
        /// OnCreate
        /// </summary>
        /// <param name="bundle"></param>
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);

                SetContentView(Resource.Layout.Main);

                _name = FindViewById<TextView>(Resource.Id.txtname);
                _mobileno = FindViewById<TextView>(Resource.Id.txtphoneno);
                _email = FindViewById<TextView>(Resource.Id.txtemailid);
                _ccno = FindViewById<TextView>(Resource.Id.txtccno);
                _login = FindViewById<Button>(Resource.Id.btnsubmit);
                _resp = new StringBuilder();
                _req = new RegistrationRequest();

                _teleMngr = (TelephonyManager)GetSystemService(TelephonyService);
                _mobileno.Text = _teleMngr.Line1Number;

                _login.Click += delegate
                {
                    if (!DoRegistrationValidation())
                    {
                        new AlertDialog.Builder(this)
                        .SetMessage(_resp.ToString())
                        .SetNeutralButton("Ok", delegate { }).Show();
                        return;
                    }

                    try
                    {
                        ConstructRequest();

                        HttpStatusCode respCode = PostRegistrationDetails(URL, _req);

                        if (respCode != HttpStatusCode.OK)
                        {
                            new AlertDialog.Builder(this)
                           .SetMessage(respCode.ToString())
                           .SetNeutralButton("Ok", delegate { }).Show();
                            return;
                        }

                    }
                    catch (Exception ex)
                    {
                        new AlertDialog.Builder(this).SetMessage(ex.Message).Show();
                    }

                    Intent intent = new Intent(this, typeof(HomeActivity));
                    intent.PutExtra("Name", _name.Text);
                    intent.PutExtra("DeviceId", _teleMngr.DeviceId);
                    StartActivity(intent);
                };
            }
            catch (Exception ex)
            {
                new AlertDialog.Builder(this).SetMessage("Oncreate main activity **culprit** "+ex.Message).Show();
            }
        }