private void dodajOdgovorButton_Click(object sender, EventArgs e) { //HttpResponseMessage response = odgovorService.GetResponse(); //List<asp_Odgovor_SelectAll_Result> odgovori = response.Content.ReadAsAsync<List<asp_Odgovor_SelectAll_Result>>().Result; if (PitanjeGridView.SelectedRows.Count == 0) { MessageBox.Show(Messages.pitanje_select_req); return; } int index = 0; for (int i = 0; i < PitanjeGridView.SelectedRows[0].Cells.Count; i++) { if (PitanjeGridView.SelectedRows[0].Cells[i].OwningColumn.Name == "PitanjeId") { index = i; break; } } bool vecPostoji = false; int pitanjeId = Convert.ToInt32(PitanjeGridView.SelectedRows[0].Cells[index].Value); HttpResponseMessage response = odgovorService.GetActionResponse("DaLiPostojiOdgovor", pitanjeId); if (response.StatusCode == System.Net.HttpStatusCode.OK) { vecPostoji = true; } else if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { vecPostoji = false; } //if (odgovori.Where(x => x.PitanjeId == Convert.ToInt32(PitanjeGridView.SelectedRows[0].Cells[index].Value)).Any()) // pitanjeId = odgovori.Where(x => x.PitanjeId == Convert.ToInt32(PitanjeGridView.SelectedRows[0].Cells[index].Value)).FirstOrDefault().PitanjeId; //if (pitanjeId != -1) //pitanjeId = 17; //else // MessageBox.Show("Pitanju su dodjeljeni već odgovori", "Poruka o uspjehu", MessageBoxButtons.OK, MessageBoxIcon.Information); OdgovorIndexForm o = new OdgovorIndexForm(Convert.ToInt32(PitanjeGridView.SelectedRows[0].Cells[index].Value), vecPostoji); if (o.ShowDialog() == DialogResult.OK) { BindForm(); } }
private void sacuvajButton_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { pitanje.TipPitanjaId = Convert.ToInt32(tipPitanjaList.SelectedValue); pitanje.Pitanje1 = pitanjeInput.Text; pitanje.TestId = Convert.ToInt32(testList.SelectedValue); HttpResponseMessage responsePitanje = pitanjeService.GetActionResponse("GetBrojPitanjaPoTestu", pitanje.TestId); int brojPitanja = responsePitanje.Content.ReadAsAsync <int>().Result; if (brojPitanja < 20) { HttpResponseMessage response = pitanjeService.PostResponse(pitanje); if (response.IsSuccessStatusCode) { HttpResponseMessage responseMessage = pitanjeService.GetResponseAction("GetLastPitanje"); Pitanjel_Result p = responseMessage.Content.ReadAsAsync <Pitanjel_Result>().Result; // MessageBox.Show(Messages.add_pitanje_succ); OdgovorIndexForm o = new OdgovorIndexForm(p.PitanjeId); o.ShowDialog(); DialogResult = DialogResult.OK; Close(); } else { string msg = response.ReasonPhrase; if (!String.IsNullOrEmpty(Messages.ResourceManager.GetString(response.ReasonPhrase))) { msg = Messages.ResourceManager.GetString(response.ReasonPhrase); } MessageBox.Show("Error Code:" + response.StatusCode + " Message: " + msg); } } else { MessageBox.Show("Nije moguće dodati više od 20 pitanja za odabrani test"); } } }