コード例 #1
0
        public async void GetCitasUser(int id)
        {
            Debug.WriteLine("-----------------------------------------------WORKED-------------------------------------");



            var uri     = "http://aige.sytes.net/APIRESTSAM/api/citasapp/getcitas?id=" + id;
            var request = new HttpRequestMessage();

            request.RequestUri = new Uri(uri);

            request.Method = HttpMethod.Get;

            var client = new HttpClient();

            // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tok_ty, acc_tok);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = await client.SendAsync(request);

            switch (response.StatusCode)
            {
            //200
            case (System.Net.HttpStatusCode.OK):

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

                memberDatabase = new MemberDatabase();
                memberDatabase.DropCitaT();
                memberDatabase.CreateCitaT();
                try
                {
                    Root myobject = JsonConvert.DeserializeObject <Root>(xjson);

                    int myobjcount = myobject.tablas.Table.Count;
                    for (int i = 0; i < myobjcount; i++)
                    {
                        var citx = new Cita();
                        citx.ID          = myobject.tablas.Table[i].idevento;
                        citx.razon       = myobject.tablas.Table[i].razon;
                        citx.descripcion = myobject.tablas.Table[i].descripcion; citx.fecha = myobject.tablas.Table[i].fecha;

                        citx.hora = myobject.tablas.Table[i].hora;
                        memberDatabase.AddCita(citx);
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("---------------------------500---------------------error" + ex);
                    return;
                }

                break;

            //500
            case (System.Net.HttpStatusCode.InternalServerError):

                Debug.WriteLine("---------------------------500---------------------error");


                break;

            //404
            case (System.Net.HttpStatusCode.Forbidden):
                Debug.WriteLine("---------------------------404---------------------error");
                break;
            }
        }
コード例 #2
0
        public async void InvitarUsuarios()
        {
            string dt  = DTP.Date.ToString("yyyy-MM-dd");;
            var    ttx = TP.Time.Hours;
            int    tms = TP.Time.Minutes;
            string tt  = ttx.ToString();

            var tmsS = tms.ToString();
            int tmsL = tmsS.Length;

            if (tmsL == 1)
            {
                tmsS = "0" + tms;
            }
            else
            {
                tmsS = tms.ToString();
            }
            lbl.Text = "Cita agendada en la fecha: " + dt + "/" + tt + ":" + tmsS;

            try
            {
                memberdatabase = new MemberDatabase();
                var    members = memberdatabase.GetMembers();
                var    member  = members.FirstOrDefault();
                var    ID      = member.ID;
                string rz      = Razon.Text;
                string desc    = Descripcion.Text;
                string IDst    = ID.ToString();

                HttpClient client = new HttpClient();

                // client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(tok_ty, acc_tok);
                client.DefaultRequestHeaders.Add("api-version", "1.0");
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));


                var values = new Dictionary <string, string>
                {
                    { "ID", IDst },
                    { "fecha", dt },
                    { "hora", tt + " :" + tmsS },
                    { "descripcion", desc },
                    { "razon", rz }
                };


                var content = new FormUrlEncodedContent(values);

                var link1 = "http://aige.sytes.net/ApiRestSAM/api/CITASAPP/CitaNueva";
                //var link2 = "http://192.168.50.18/ApiRestSAM/api/CITASAPP/CitaNueva";
                var response = await client.PostAsync(link1, content);

                switch (response.StatusCode)
                {
                case (System.Net.HttpStatusCode.OK):

                    var responseString = await response.Content.ReadAsStringAsync();



                    // var xjson = JsonConvert.DeserializeObject(responseString);
                    var xjson = JsonConvert.DeserializeObject <Root>(responseString);

                    int eventoid = Convert.ToInt32(xjson.tablas.Table1[0].Eventoid);
                    cita             = new Cita();
                    cita.descripcion = Descripcion.Text;
                    cita.fecha       = dt;
                    cita.razon       = rz;
                    cita.hora        = tt;
                    cita.ID          = eventoid;
                    cita.descripcion = desc;



                    memberdatabase.AddCita(cita);

                    int idcita = eventoid;
                    int myid   = ID;
                    await DisplayAlert("Cita generada", "Elija a los usuarios con los que desea compartir esta cita", "Entiendo");

                    await Navigation.PushAsync(new InvitarUsers(idcita, myid));

                    break;

                case (System.Net.HttpStatusCode.NotFound):
                    f**k.Text = "Error 404";
                    break;

                case (System.Net.HttpStatusCode.BadRequest):
                    f**k.Text = "Error 400";
                    break;

                case (System.Net.HttpStatusCode.Forbidden):
                    f**k.Text = "Error 403";
                    break;

                //500
                case (System.Net.HttpStatusCode.InternalServerError):
                    string status = "Nuestros servidores estan en mantenimiento";
                    f**k.Text = status;
                    break;
                }
            }
            catch (Exception ex)
            {
                f**k.Text = ex.ToString();
            }
        }