private async Task crearPro_Clicked(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(nombreProyectoEntry.Text))
            {
                if (await getProjects(nombreProyectoEntry.Text) == false)
                {
                    var client = new HttpClient
                    {
                        BaseAddress = new Uri("https://app-produ.herokuapp.com")
                    };
                    var newProject = new Project
                    {
                        nombre      = nombreProyectoEntry.Text,
                        descripcion = descripcionProyectoEditor.Text,
                        user_id     = (int)Application.Current.Properties["id"],
                        token       = Application.Current.Properties["currentToken"].ToString()
                    };
                    string jsonData = JsonConvert.SerializeObject(newProject);
                    var    content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

                    HttpResponseMessage response = await client.PostAsync("/projects/newproject.json", content);

                    if (response.StatusCode == HttpStatusCode.Created)
                    {
                        var result = await response.Content.ReadAsStringAsync();

                        var jobject = JObject.Parse(result);
                        var data    = JsonConvert.DeserializeObject <Project>(jobject["proyecto"].ToString());


                        try
                        {
                            Application.Current.Properties["id-project"] = data.id;
                            var muestreosPage = new Muestreos();
                            await Navigation.PushAsync(muestreosPage);

                            this.Navigation.RemovePage(this.Navigation.NavigationStack[this.Navigation.NavigationStack.Count - 2]);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Error!", "El nombre del proyecto ya existe.", "OK");
                }
            }
            else
            {
                await DisplayAlert("Error!", "Espacios vacíos!\nPor favor inserte el Nombre del Proyecto!", "OK");
            }
        }
Пример #2
0
        async void Handle_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            if (e.Item == null)
            {
                return;
            }

            var temp   = (Project)e.Item;
            var idType = MyListView;

            Application.Current.Properties["id-project"] = temp.id;
            var muestreoPage = new Muestreos();
            await Navigation.PushAsync(muestreoPage);

            //Deselect Item
            ((ListView)sender).SelectedItem = null;
        }