public ActionResult Create(LevelModel model, int Institution) { try { using (ISession session = NHibernateHelper.OpenSession()) { InstitutionModel institutionModel = session.Get<InstitutionModel>(Institution); model.Institution = institutionModel; using (ITransaction transaction = session.BeginTransaction()) { session.Save(model); transaction.Commit(); } } return RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"); } catch { return RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"); throw; } }
public ActionResult Edit(LevelModel model, int Institution) { try { using (ISession session = NHibernateHelper.OpenSession()) { LevelModel persistentModel = session.Get<LevelModel>(model.Id); InstitutionModel institutionModel = session.Get<InstitutionModel>(Institution); persistentModel.Institution = institutionModel; persistentModel.Name = model.Name; persistentModel.LevelType = model.LevelType; using (ITransaction transaction = session.BeginTransaction()) { session.Save(persistentModel); transaction.Commit(); } } return RedirectToAction("Index").WithMessage(Languages.Success, "alert-success", "glyphicon glyphicon-ok-sign"); } catch(PropertyValueException) { return RedirectToAction("Index").WithMessage(Languages.Error, "alert-warning", "glyphicon glyphicon-exclamation-sign"); throw; } catch (System.Exception) { return RedirectToAction("Index").WithMessage(Languages.Error, "alert-danger", "glyphicon glyphicon-remove-sign"); throw; } }