public void TesteSalvateInBazaDeDateUDI(TesteSalvateInBazaDeDate test) { using (var context = new ModelContext()) { context.TesteSalvateInBazaDeDates.Add(test); foreach (var entry in context.ChangeTracker.Entries <BaseEntity>()) { entry.State = EntityConvertState.ConvertState(entry.Entity.State); if (entry.State == EntityState.Modified) { entry.State = EntityState.Unchanged; var databaseValues = entry.GetDatabaseValues(); entry.OriginalValues.SetValues(databaseValues); } } context.SaveChanges(); } }
public ActionResult CorecteazaTest() { string prevBtn = Request.Form["prevBtn"]; string nextBtn = Request.Form["nextBtn"]; if (prevBtn != null) { int index = Convert.ToInt32(Session["IndexIntrebareCurenta"].ToString()); if (index <= 0) { Session["IndexIntrebareCurenta"] = 0; } else { Session["IndexIntrebareCurenta"] = index - 1; } } if (nextBtn != null) { int index = Convert.ToInt32(Session["IndexIntrebareCurenta"].ToString()); if (index + 1 >= Convert.ToInt32(Session["numarIntrebariTest"].ToString())) { Session["IndexIntrebareCurenta"] = index; } else { Session["IndexIntrebareCurenta"] = index + 1; } } string testSelectat = Request.Form["testSelectat"]; if (testSelectat != null) { Session["testSelectat"] = testSelectat; var lista = serviciu.GetListaCursantiCareAuDatTestulCreatDeLectorByNumeTest(Session["testSelectat"].ToString()).Select(s => s.ContCursant).ToList(); Session["ViewBag.testSelectat"] = lista; } string IncepeCorectareTest = Request.Form["IncepeCorectareTest"]; if (IncepeCorectareTest != null) { Session["IncepeCorectareTest"] = true; Session["CursantCuTestDeCorectat"] = Request.Form["cursantTestSelectat"]; //cursantTestSelectat Session["IndexIntrebareCurenta"] = 0; var vTestCreatDeLector = serviciu.GetTestCreatDeLectorByName(Session["testSelectat"].ToString()); var vCursant = serviciu.GetCursantByCont(Session["CursantCuTestDeCorectat"].ToString()); var lista = serviciu.GetListaTesteSalvateInBazaDeDateByID_CURSANT_ID_TestCreatDeLector(vCursant.IdCursant, vTestCreatDeLector.IdTest); Session["numarIntrebariTest"] = lista.Length; for (int i = 0; i < lista.Length; i++) { Session["TDCintrebare" + i] = lista[i]; } } var ceva = serviciu.GetListaTesteCreateDeLector().ToList(); List <string> listaTeste = new List <string>(); foreach (var a in ceva) { listaTeste.Add(a.NumeTest); } ViewBag.listTeste = listaTeste; TesteSalvateInBazaDeDate test = null; if (Session["IndexIntrebareCurenta"] != null) { int index = Convert.ToInt32(Session["IndexIntrebareCurenta"].ToString()); test = (TesteSalvateInBazaDeDate)Session["TDCintrebare" + index]; } if (test == null) { Session["IndexIntrebareCurenta"] = null; } return(View(test)); }
public ActionResult RezolvaTestul() { string numeTestProgramat = Session["numeTestProgramat"].ToString(); if (Session["amIncarcatDatele"] == null) { Session["amIncarcatDatele"] = "da"; var listaIntrebari = serviciu.GetListaIntrebariRaspunsuriTestProgramatByNumeTestProgramat(numeTestProgramat); var contCursant = serviciu.GetCursantByCont(Session["logareCursant"].ToString()); Session["IntrebariTest"] = listaIntrebari.Length; int indexIntrebare = 1; foreach (var v in listaIntrebari) { GrupareRezolvareTest g = new GrupareRezolvareTest(); g.intrebareObj = v; g.index = indexIntrebare; Session["intrebare" + indexIntrebare] = g; indexIntrebare++; } Session["indexIntrebareCurenta"] = 1; } string prevBtn = Request.Form["prevBtn"]; string nextBtn = Request.Form["nextBtn"]; if (prevBtn != null) { string justificare = Request.Form["justificare"]; if (justificare != null) { GrupareRezolvareTest ggPrev = (GrupareRezolvareTest)Session["intrebare" + Session["indexIntrebareCurenta"]]; ggPrev.justificare = justificare; // o sa construim raspunsul string raspuns = ""; for (int i = 0; i < ggPrev.intrebareObj.Raspunsuris.Length; i++) { bool exista = Request.Form[i.ToString()] != null; if (exista) { raspuns += "1"; } else { raspuns += "0"; } } ggPrev.raspuns = raspuns; Session["intrebare" + Session["indexIntrebareCurenta"]] = ggPrev; } int nr = Convert.ToInt32(Session["indexIntrebareCurenta"].ToString()); if (nr == 1) { } else { nr--; } Session["indexIntrebareCurenta"] = nr; } if (nextBtn != null) { string justificare = Request.Form["justificare"]; if (justificare != null) { GrupareRezolvareTest ggNext = (GrupareRezolvareTest)Session["intrebare" + Session["indexIntrebareCurenta"]]; ggNext.justificare = justificare; // o sa construim raspunsul string raspuns = ""; for (int i = 0; i < ggNext.intrebareObj.Raspunsuris.Length; i++) { bool exista = Request.Form[i.ToString()] != null; if (exista) { raspuns += "1"; } else { raspuns += "0"; } } ggNext.raspuns = raspuns; Session["intrebare" + Session["indexIntrebareCurenta"]] = ggNext; } int nr = Convert.ToInt32(Session["indexIntrebareCurenta"].ToString()); if (nr == Convert.ToInt32(Session["IntrebariTest"].ToString())) { } else { nr++; } Session["indexIntrebareCurenta"] = nr; } GrupareRezolvareTest gg = (GrupareRezolvareTest)Session["intrebare" + Session["indexIntrebareCurenta"]]; // nu pot obtine obiectul // de verificat bool putemSalvaInBazaDeDate = true; for (int i = 1; i <= Convert.ToInt32(Session["IntrebariTest"].ToString()); i++) { GrupareRezolvareTest ggSalvareBazaDate = (GrupareRezolvareTest)Session["intrebare" + i.ToString()]; if (ggSalvareBazaDate.justificare == null) { putemSalvaInBazaDeDate = false; } else if (ggSalvareBazaDate.justificare.Length == 0) { putemSalvaInBazaDeDate = false; } } bool salvatiTestulInBazaDeDate = Request.Form["salvatiTestulInBazaDeDate"] != null; if (salvatiTestulInBazaDeDate) { string cont = Session["logareCursant"].ToString(); var cursant = serviciu.GetCursantByCont(cont); var testProgramat = serviciu.GetProgramareTestByName(numeTestProgramat); for (int i = 1; i <= Convert.ToInt32(Session["IntrebariTest"].ToString()); i++) { GrupareRezolvareTest v = (GrupareRezolvareTest)Session["intrebare" + i.ToString()]; TesteSalvateInBazaDeDate test = new TesteSalvateInBazaDeDate { CursantiIdCursant = cursant.IdCursant, IntrebariIdIntrebare = v.intrebareObj.IdIntrebare, TestCreatDeLectorIdTest = testProgramat.TestCreatDeLectorIdTest, Raspuns = v.raspuns, MotivareRaspuns = v.justificare }; serviciu.TesteSalvateInBazaDeDateUDI(test); } serviciu.DeleteFromListaCursantiTestProgramats(testProgramat.Id, cursant.IdCursant); Session.Clear(); Session["testSalvaInBazaDeDate"] = true; return(RedirectToAction("Index", "Cursant")); } ViewBag.putemSalvaInBazaDeDate = putemSalvaInBazaDeDate; return(View(gg)); }