protected void Page_Load(object sender, EventArgs e) { string id = Session["idUtente"].ToString(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); var responseTask = client.GetAsync("clienti?idUtente=" + id); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); clsClienti c = JsonConvert.DeserializeObject <clsClienti>(readTask.Result); email = c.email; lblUsername.Text = email; caricaDdl(); } else { lblMsg.Text = result.StatusCode.ToString(); } }
protected void Button1_Click(object sender, EventArgs e) { try { if (txtCognome.Text != "" && txtNome.Text != "") { string nome = txtNome.Text; string cognome = txtCognome.Text; int a; int pm, p; string id = Session["idUtente"].ToString(); a = Convert.ToInt32(ddlAltezza.Text); pm = Convert.ToInt32(ddlPercentualeMassaGrassa.Text); p = Convert.ToInt32(ddlPeso.Text); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); clsClienti cliente = new clsClienti(); cliente.nome = nome; cliente.idCliente = Convert.ToInt32(id); cliente.cognome = cognome; cliente.altezza = a; cliente.peso = p; cliente.pMassaGrassa = pm; var postTask = client.PostAsJsonAsync <clsClienti>("clienti", cliente); var result = postTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); Response.Redirect("aggiornamentoSuccesso.aspx", false); } } else { lblMsg.Text = "ERRORE: i campi nome, cognome, email possono risultare incompleti"; } } catch (Exception ex) { lblMsg.Text = "ERRORE: " + ex.Message; } }
protected void btnRegistraRapido_Click(object sender, EventArgs e) { try { if (txtCognome.Text != "" && txtNome.Text != "" && txtEmail.Text != "") { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(uri); //HTTP GET var responseTask = client.GetAsync("clienti?Email=" + txtEmail.Text); responseTask.Wait(); var result = responseTask.Result; if (result.IsSuccessStatusCode) { var readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); bool esiste = Convert.ToBoolean(readTask.Result); if (!esiste) { responseTask = client.GetAsync("password"); responseTask.Wait(); result = responseTask.Result; if (result.IsSuccessStatusCode) { readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); var pwdJson = readTask.Result; clsPwd p = JsonConvert.DeserializeObject <clsPwd>(pwdJson); clsPwd pass = new clsPwd(); string passChiara = p.pwd; pass.pwd = p.pwd; var postTask = client.PostAsJsonAsync <clsPwd>("password", pass); postTask.Wait(); result = postTask.Result; if (result.IsSuccessStatusCode) { readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); pwdJson = readTask.Result; p = JsonConvert.DeserializeObject <clsPwd>(pwdJson); string cryptoPwd = p.pwd; clsClienti cliente = new clsClienti(); string email = txtEmail.Text; string nome = txtNome.Text; string cognome = txtCognome.Text; cliente.nome = nome; cliente.cognome = cognome; cliente.email = email; cliente.pwd = cryptoPwd; postTask = client.PostAsJsonAsync <clsClienti>("clienti", cliente); result = postTask.Result; if (result.IsSuccessStatusCode) { readTask = result.Content.ReadAsStringAsync(); readTask.Wait(); lblMsg.Text = "Cliente inserito con successo!"; inviaMailPwd(nome, cognome, email, passChiara); } else { lblMsg.Text = result.StatusCode.ToString(); } } else { lblMsg.Text = result.StatusCode.ToString(); } } else { lblMsg.Text = result.StatusCode.ToString(); } } else { lblMsg.Text = "ERRORE: account già esistente con questa mail"; } } else { lblMsg.Text = result.StatusCode.ToString(); } } else { lblMsg.Text = "ERRORE: i campi nome, cognome, email possono risultare incompleti"; } } catch (Exception ex) { lblMsg.Text = "ERRORE: " + ex.Message; } }