public ActionResult Close(TripClosureViewModel tcvm) { if (!tcvm.TripId.HasValue) { return new NoSuchTripResult(); } var repo = new TubsRepository<Trip>(MvcApplication.CurrentSession); var trip = repo.FindBy(tcvm.TripId.Value); if (null == trip) { return new NoSuchTripResult(); } // Idempotent -- if the trip is already closed, just push to the details page if (!trip.IsReadOnly) { trip.ClosedDate = DateTime.Now; trip.Comments = tcvm.Comments; try { repo.Update(trip); } catch (Exception ex) { Flash("Unable to close trip -- contact technical support"); Logger.Error("Error while closing trip", ex); } } // Pull page just for closing trip. Modal is fine, although may want to make it larger. //return View(tcvm); return RedirectToAction("Details", "Trip", new { tripId = trip.Id }); }
public static void FillDependentObjects(this Trip trip, TripHeaderViewModel thvm, ISession session) { if (null != trip && null != thvm && null != session) { if (thvm.VesselId != default(int)) { var vesselRepo = new TubsRepository<Vessel>(session); trip.Vessel = vesselRepo.FindBy(thvm.VesselId); } var staffRepo = new TubsRepository<Observer>(session); trip.Observer = staffRepo.FindBy(thvm.ObserverCode); var portRepo = new TubsRepository<Port>(session); trip.DeparturePort = portRepo.FindBy(thvm.DeparturePortCode); trip.ReturnPort = portRepo.FindBy(thvm.ReturnPortCode); } }
public void AddTripMonitor() { const string userName = "******"; DateTime enteredDate = DateTime.Now; int headerId = default(int); using (var session = TubsDataService.GetSession()) { using (var transaction = session.BeginTransaction()) { // Find the first trip for which Dave J. Burgess is the observer var trip = new TubsRepository<Trip>(session).FilterBy(t => t.Observer.StaffCode == "DJB").FirstOrDefault(); Assert.NotNull(trip); // Create new, empty, GEN-3 var header = new TripMonitor(); header.Question1 = false; header.EnteredBy = userName; header.EnteredDate = enteredDate; header.Trip = trip; // Add a child record var detail = new TripMonitorDetail(); detail.DetailDate = trip.DepartureDate.HasValue ? trip.DepartureDate.Value : trip.DepartureDateOnly.Value; detail.Comments = "Xyzzy"; detail.EnteredBy = userName; detail.EnteredDate = enteredDate; header.AddDetail(detail); Assert.True(new TubsRepository<TripMonitor>(session).Add(header)); headerId = header.Id; Assert.False(default(int) == header.Id); transaction.Commit(); } } // Delete the entity afterwards using (var session = TubsDataService.GetSession()) { using (var transaction = session.BeginTransaction()) { var repo = new TubsRepository<TripMonitor>(session); var header = repo.FindBy(headerId); Assert.NotNull(header); Assert.NotNull(header.Trip); Assert.NotNull(header.Details); Assert.True(header.Question1.HasValue); Assert.False(header.Question1.Value); var child = header.Details[0]; Assert.NotNull(child); Assert.AreEqual(userName, child.EnteredBy); Assert.True(repo.Delete(header)); transaction.Commit(); } } }