Ejemplo n.º 1
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            string parameter;

            if (NavigationContext.QueryString.TryGetValue("id", out parameter))
            {
                HttpClient httpClient = new HttpClient();
                httpClient.BaseAddress = new Uri(ip);

                var response = await httpClient.GetAsync("/20131011110061/api/grupousuario");

                var str = response.Content.ReadAsStringAsync().Result;
                List <Models.Grupo> obj = JsonConvert.DeserializeObject <List <Models.Grupo> >(str);
                grupo = obj.Where(g => g.Id == int.Parse(parameter)).Single();

                txtDescricao.Text = grupo.Descricao;

                getUsuarios();
            }
            else
            {
                NavigationService.GoBack();
            }
        }
        private async void btnCriarGrupo_Click(object sender, RoutedEventArgs e)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ip);

            Models.Grupo g = new Models.Grupo
            {
                Descricao = txtNomeGrupo.Text,
                IdAdm     = (ListaUsuariosAdm.SelectedItem as Models.Usuario).Id
            };
            string s        = JsonConvert.SerializeObject(g);
            var    content  = new StringContent(s, Encoding.UTF8, "application/json");
            var    response = await httpClient.PostAsync("/20131011110061/api/grupousuario", content);

            //Fazer a piruletagem para pegar o id do grupo quando criar

            Models.RelGrupoUsuario rel = new Models.RelGrupoUsuario
            {
                Usuario_Id      = g.IdAdm,
                GrupoUsuario_Id = int.Parse(await response.Content.ReadAsStringAsync())
            };

            string s2        = JsonConvert.SerializeObject(rel);
            var    content2  = new StringContent(s2, Encoding.UTF8, "application/json");
            var    response2 = await httpClient.PostAsync("/20131011110061/api/relgrupousuario", content2);

            MessageBox.Show("Acho que criou");


            //getDados();
        }
Ejemplo n.º 3
0
        private async void btnEditarGrupo_Click(object sender, RoutedEventArgs e)
        {
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ip);

            var response = await httpClient.GetAsync("/20131011110061/api/grupousuario");

            var str = response.Content.ReadAsStringAsync().Result;
            List <Models.Grupo> obj = JsonConvert.DeserializeObject <List <Models.Grupo> >(str);

            Models.Grupo u = (from Models.Grupo g in obj where g.Id == grupo.Id select g).Single();
            u.Descricao = txtDescricao.Text;

            string s       = JsonConvert.SerializeObject(u);
            var    content = new StringContent(s, Encoding.UTF8,
                                               "application/json");
            await httpClient.PutAsync("/20131011110061/api/grupousuario/" + grupo.Id, content);

            MessageBox.Show("Acho que editou");
        }