//public ActionResult Delete(int id) // { // return View(); //} //[HttpPost] public ActionResult DeleteStudent(int id, FormCollection collection) { if (this.Session["UserProfile"] == null) { return(RedirectToAction("Index", "Home")); } int id2; try { using (ISession session = NhibernateSession.OpenSession()) { //ISQLQuery s = session.CreateSQLQuery("select ku.klasa_id from klasauczen ku where ku.uzytkownik_id=" + id); KlasaUczen ku = session.Query <KlasaUczen>().Where(b => b.Uzytkownik.id == id).First(); id2 = ku.Klasa.id; KlasaUczen klasaUczen = session.Query <KlasaUczen>().Where(c => c.Uzytkownik.id == id).First(); using (ITransaction trans = session.BeginTransaction()) { session.Delete(klasaUczen); trans.Commit(); } } return(RedirectToAction("EditStudents", "Klasy", new { id = id2 })); } catch (Exception e) { return(View()); } }
public ActionResult Add(KlasaUczen model) { if (this.Session["UserProfile"] == null) { return(RedirectToAction("Index", "Home")); } KlasaUczen ku = new KlasaUczen(); try { using (ISession session = NhibernateSession.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { session.Save(model); transaction.Commit(); } } return(RedirectToAction("IndexAdmin")); } catch (Exception e) { return(View()); } }