Example #1
0
        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 });
        }
Example #2
0
        /// <summary>
        /// BindModel binds the trip entity.
        /// </summary>
        /// <param name="controllerContext"></param>
        /// <param name="bindingContext"></param>
        /// <returns>Trip model if Id represents existing trip, null otherwise.</returns>
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ValueProviderResult value = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);

            if (null == value)
            {
                return null;
            }

            if (String.IsNullOrEmpty(value.AttemptedValue))
            {
                return null;
            }

            int entityId;

            if (!Int32.TryParse(value.AttemptedValue, out entityId))
            {
                return null;
            }
            // Set TripId in ViewBag regardless of existence of Trip.
            controllerContext.Controller.ViewBag.TripId = entityId;
            // FIXME
            // This is a _BRUTAL HACK_
            // NHibernate session filters aren't used when looking up an entity directly by primary key.
            // However, if we change the API, we can force the use of a session filter
            // See the SimpleTripFilter, SimpleTripHeaderFilter, and SimpleTripFilterWithFindBy unit tests in the DAL project for more details.
            var trip = new TubsRepository<Trip>(MvcApplication.CurrentSession).FindBy(t => t.Id == entityId);
            // FIXME The following line is the original version and can be re-enabled when the DAL has a better security implementation
            //var trip = new TubsRepository<Trip>(MvcApplication.CurrentSession).FindBy(entityId);
            // ReadOnly is nonsense for a non-existant trip, but for the sake of completeness, we want
            // to ensure that IsReadOnly is present in the ViewBag
            controllerContext.Controller.ViewBag.IsReadOnly = (null == trip) ? true : trip.IsReadOnly;
            return trip;
        }
Example #3
0
        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();
                }
            }
        }
 public void ModifyVesselAttributes()
 {
     var transaction = this.session.BeginTransaction();
     var trip = new TubsRepository<Trip>(this.session).FindBy(103) as PurseSeineTrip;
     Assert.NotNull(trip);
     var attributes = trip.VesselAttributes;
     Assert.NotNull(attributes);
     attributes.HelicopterMake = "Hughes";
     attributes.HelicopterModel = "MD 500 Defender";
     var repo = new TubsRepository<PurseSeineVesselAttributes>(this.session);
     repo.Update(attributes);
     transaction.Commit();
 }
Example #5
0
        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);
            }
        }
Example #6
0
 public ActionResult List(Trip tripId)
 {
     var repo = new TubsRepository<SeaDay>(MvcApplication.CurrentSession);
     // Push the projection into a List so that it's not the NHibernate collection implementation
     var days = repo.FilterBy(d => d.Trip.Id == tripId.Id).ToList<SeaDay>();
     ViewBag.Title = String.Format("Sea days for {0}", tripId.ToString());
     ViewBag.TripNumber = tripId.SpcTripNumber ?? "This Trip";
     return View(days);
 }
 public void Setup()
 {
     this.repo = new TubsRepository<Port>(TubsDataService.GetSession());
 }