public async Task <IActionResult> Edit(int id, [Bind("IntrebareId,UtilizatorId,Data,Continut")] Intrebare intrebare) { if (id != intrebare.IntrebareId) { return(NotFound()); } if (ModelState.IsValid) { try { intrebareService.UpdateIntrebare(intrebare); } catch (DbUpdateConcurrencyException) { if (!intrebareService.IntrebareExists(intrebare.IntrebareId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UtilizatorId"] = new SelectList(intrebareService.GetAllUtilizatori(), "Id", "Nume", intrebare.UtilizatorId); return(View(intrebare)); }
public ActionResult DeleteConfirmed(int id) { Intrebare intrebare = db.Intrebari.Find(id); db.Intrebari.Remove(intrebare); db.SaveChanges(); return(RedirectToAction("Index")); }
protected void Page_Load(object sender, EventArgs e) { using (var ctx = new TalantContext()) { _listIntrebari = ctx.Intrebari.Where(intr => intr.Id > 38).ToList(); } FleckLog.Level = LogLevel.Debug; var server = new WebSocketServer("ws://127.0.0.1:8181"); int raspuns = 0; server.Start(socket => { socket.OnOpen = () => { var user = socket.ConnectionInfo.Path.Remove(0, 1); Profil conexiune = new Profil { Socket = socket, UserName = user, Color = GetRandomColor() }; allSockets.Add(conexiune); allSockets.ToList().ForEach(s => s.Socket.Send(conexiune.UserName + " a intrat.")); }; socket.OnClose = () => { System.Diagnostics.Debug.WriteLine("Close!"); var conexiune = allSockets.Where(s => s.Socket == socket).FirstOrDefault(); allSockets.Remove(conexiune); allSockets.ToList().ForEach(s => s.Socket.Send(conexiune.UserName + " a iesit.")); }; socket.OnMessage = message => { Mesaj mesaj = new JavaScriptSerializer().Deserialize <Mesaj>(message); System.Diagnostics.Debug.WriteLine(message); allSockets.ToList().ForEach(s => s.Socket.Send(FormatMessage(mesaj))); if (mesaj.Content == _randomIntrebare.Raspuns.ToString()) { allSockets.ToList().ForEach(s => s.Socket.Send(mesaj.User + "WIN!!!")); } }; }); while (true) { System.Threading.Thread.Sleep(5000); Random rnd = new Random(); int r = rnd.Next(_listIntrebari.Count); _randomIntrebare = _listIntrebari[r]; allSockets.ToList().ForEach(s => s.Socket.Send(_randomIntrebare.Enunt)); } }
private void generareIntrebare() { ClearIntrebare(); Intrebare i = new Intrebare(); i.IntrebareId = Convert.ToInt32(intrebari.Rows[linie][0]); DataTable dt = i.SelectIntrebariTip2(i); labelEnuntTip2.Text = dt.Rows[0][1].ToString(); Random rnd = new Random(); int A1 = rnd.Next(2, 5); int A2; do { A2 = rnd.Next(2, 5); } while (A2 == A1); int A3; if ((A1 == 2 && A2 == 3) || (A1 == 3 && A2 == 2)) { A3 = 4; } else if ((A1 == 2 && A2 == 4) || (A1 == 4 && A2 == 2)) { A3 = 3; } else { A3 = 2; } buttonA.Text = dt.Rows[0][A1].ToString(); buttonB.Text = dt.Rows[0][A2].ToString(); buttonC.Text = dt.Rows[0][A3].ToString(); foreach (char c in dt.Rows[0][5].ToString()) { if (c == 'A') { raspunsCorect += dt.Rows[0][2].ToString(); } else if (c == 'B') { raspunsCorect += dt.Rows[0][3].ToString(); } else if (c == 'C') { raspunsCorect += dt.Rows[0][4].ToString(); } } }
public ActionResult Edit([Bind(Include = "Id,Enunt,Image,Path_Icon,Var1,Var2,Var3,Var4,IstrueVar1,IstrueVar2,IstrueVar3,IstrueVar4")] Intrebare intrebare) { if (ModelState.IsValid) { db.Entry(intrebare).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(intrebare)); }
public ActionResult Create([Bind(Include = "Id,Enunt,Image,Path_Icon,Var1,Var2,Var3,Var4,IstrueVar1,IstrueVar2,IstrueVar3,IstrueVar4")] Intrebare intrebare) { if (ModelState.IsValid) { db.Intrebari.Add(intrebare); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(intrebare)); }
public async Task <IActionResult> Create([Bind("IntrebareId,Data,Continut")] Intrebare intrebare) { var utilizator = await utilizatorService.GetCurrentUser(HttpContext.User); if (ModelState.IsValid) { intrebareService.Create(intrebare, utilizator); return(RedirectToAction(nameof(Index))); } return(View(intrebare)); }
// GET: Gfest/Intrebari/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Intrebare intrebare = db.Intrebari.Find(id); if (intrebare == null) { return(HttpNotFound()); } return(View(intrebare)); }
private void PuneAltaIntrebare() { // System.Diagnostics.Debugger.Launch(); // Console.sh // System.Threading.Thread.Sleep(5000); Random rnd = new Random(); int r = rnd.Next(_listIntrebari.Count); Intrebare intreb = new Intrebare { Enunt = "Ce??", Raspuns = "da" }; _listIntrebari.Add(intreb); _randomIntrebare = _listIntrebari[r]; allSockets.ToList().ForEach(s => s.Socket.Send(FormatMessageIntrebare(_randomIntrebare.Enunt))); // if (ss > 3) ;// ii++; }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridView1.DataSource = _listIntrebari; // GridView1.DataBind(); GridViewRow row = GridView1.Rows[e.RowIndex]; int intrebareId = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]); string tip = (row.Cells[2].Controls[0] as TextBox).Text; string categorie = (row.Cells[3].Controls[0] as TextBox).Text; string enunt = (row.Cells[4].Controls[0] as TextBox).Text; string punctaj = (row.Cells[5].Controls[0] as TextBox).Text; string editie = (row.Cells[6].Controls[0] as TextBox).Text; string raspuns = (row.Cells[7].Controls[0] as TextBox).Text; using (var ctx = new TalantContext()) { var intrebare = ctx.Intrebari.FirstOrDefault(a => a.Id == intrebareId); if (intrebare == null) { intrebare = new Intrebare(); ctx.Intrebari.Add(intrebare); } intrebare.Tip = Convert.ToInt16(tip); intrebare.Categorie = Convert.ToInt16(categorie); intrebare.Enunt = Convert.ToString(enunt); intrebare.Punctaj = Convert.ToInt16(punctaj); intrebare.Editie = Convert.ToInt16(editie); intrebare.Raspuns = Convert.ToString(raspuns); ctx.SaveChanges(); _listIntrebari = ctx.Intrebari.ToList(); GridView1.DataSource = _listIntrebari; } GridView1.EditIndex = -1; GridView1.DataBind(); }
private void TestareNivel(int capitol) { linie = 0; contor = 0; intrebari = null; Intrebare i = new Intrebare(); i.Id = capitol; intrebari = i.Testare(i); if (intrebari.Rows.Count > 0) { generareIntrebare(); } else { if (capitoleTerminate > 0) { if (capitoleTerminate >= 4) { Utilizator u = new Utilizator(); u.UserName = textBoxUtilizatorProfilNou.Text; u.AdaugareRealizare(u, 8); } rol = 1; panelLoading.BringToFront(); timerLogin.Enabled = true; timerLogin.Start(); } else { rol = 1; panelLoading.BringToFront(); timerLogin.Enabled = true; timerLogin.Start(); } } }
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Intrebare intreb = _listIntrebari.LastOrDefault(); if (intreb.Id == 0 && e.Row.RowIndex == _listIntrebari.Count - 1) { LinkButton button1 = (LinkButton)e.Row.Cells[0].Controls[0]; button1.Text = "Save"; } if (e.Row.RowType == DataControlRowType.DataRow) { TextBox txtb = e.Row.FindControl("TextBox") as TextBox; // txtb.Width = 10; } // e.Row.Cells[0].Attributes["width"] = "150px"; // e.Row.Cells[1].Attributes["width"] = "200px"; // e.Row.Cells[2].Attributes["width"] = "300px"; e.Row.Cells[4].Attributes["width"] = "500px"; // GridView1.Columns[0].ItemStyle.Width = 50; // GridView1.Columns[3].ItemStyle.Width = 50; // GridView1.Columns[4].ItemStyle.Width = 50; } }
private void buttonVerificareIntrebare_Click(object sender, EventArgs e) { if (raspunsA != null || raspunsB != null || raspunsC != null) { linie++; Intrebare i = new Intrebare(); i.UserName = textBoxUtilizatorProfilNou.Text; i.IntrebareId = Convert.ToInt32(intrebari.Rows[0][0]); if (raspunsA + raspunsB + raspunsC == raspunsCorect || raspunsA + raspunsC + raspunsB == raspunsCorect || raspunsB + raspunsA + raspunsC == raspunsCorect || raspunsB + raspunsC + raspunsA == raspunsCorect || raspunsC + raspunsA + raspunsB == raspunsCorect || raspunsC + raspunsB + raspunsA == raspunsCorect || raspunsA + raspunsB + raspunsC == raspunsCorect || raspunsA + raspunsC + raspunsB == raspunsCorect || raspunsB + raspunsA + raspunsC == raspunsCorect || raspunsB + raspunsC + raspunsA == raspunsCorect || raspunsC + raspunsA + raspunsB == raspunsCorect || raspunsC + raspunsB + raspunsA == raspunsCorect) { using (SoundPlayer audio = new SoundPlayer(bitQuiz.Properties.Resources.correct)) { audio.Play(); } contor++; if (contor == intrebari.Rows.Count) { Utilizator u = new Utilizator(); u.UserName = textBoxUtilizatorProfilNou.Text; u.Descriere = intrebari.Rows[0][2].ToString(); u.FinalizareCapitol(u); capitol++; capitoleTerminate++; TestareNivel(capitol); } else { generareIntrebare(); } i.Raspuns = 0; i.InserareIntrebareUtilizator(i); } else { using (SoundPlayer audio = new SoundPlayer(bitQuiz.Properties.Resources.wrong)) { audio.Play(); } i.Raspuns = 1; i.InserareIntrebareUtilizator(i); capitol++; TestareNivel(capitol); } } else { Eroare.textEroare = "Nicio variantă selectată"; using (Eroare er = new Eroare { StartPosition = FormStartPosition.CenterParent }) { er.ShowDialog(this); } } }
public void UpdateIntrebare(Intrebare intrebare) { _repo.Intrebare.Update(intrebare); _repo.Save(); }
public void Create(Intrebare intrebare, Utilizator utilizator) { intrebare.UtilizatorId = utilizator.Id; _repo.Intrebare.Create(intrebare); _repo.Save(); }