public TestCabinDAO() { Session = NHibernateHelper.OpenSession(true); var factory = new NHibernateDAOFactory(Session); Dao = _cabinDao = factory.getCabinDAO(); _passDao = factory.getPassengerDAO(); }
public ActionResult Edit(int id) { using (var session = NHibernateHelper.OpenSession()) { var factory = new NHibernateDAOFactory(session); var passDao = factory.getPassengerDAO(); var p = passDao.GetById(id); var cab = p.Cabin; ViewBag.Message = $"Cabin: {cab.CabinName}. Editing passenger: {p.FirstName} {p.LastName}"; return(View("Index", new Tuple <int, IEnumerable <Passenger>, Passenger>( cab.Id, new List <Passenger>(passDao.GetPassengerByCabin(cab.Id)), p ))); } }
public ActionResult PostPassenger(int cabinId, Passenger passenger) { using (var session = NHibernateHelper.OpenSession()) { var daoFactory = new NHibernateDAOFactory(session); var passengerCabin = daoFactory.getCabinDAO().GetById(cabinId); if (passengerCabin == null) { throw new NullReferenceException("Cabin can't be null!"); } passenger.Cabin = passengerCabin; daoFactory.getPassengerDAO().SaveOrUpdate(passenger); } return(RedirectToAction("GetByCabin", new { cabinId })); }
public ActionResult GetByCabin(int cabinId) { using (var session = NHibernateHelper.OpenSession()) { var factory = new NHibernateDAOFactory(session); var pass = factory.getPassengerDAO(); var cab = factory.getCabinDAO(); var cabin = cab.GetById(cabinId); ViewBag.Message = $"Cabin: {cabin.CabinName}."; return(View("index", new Tuple <int, IEnumerable <Passenger>, Passenger>( cabinId, new List <Passenger>(pass.GetPassengerByCabin(cabinId)), new Passenger { Cabin = cabin } ))); } }