// GET: Sequences/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sequence sequence = db.Sequences.Find(id); if (sequence == null) { return(HttpNotFound()); } SequenceDisp sDisp = new SequenceDisp(); sDisp.CopyData(sequence); sDisp.Region = (from r in db.Regions where r.RegionID == sequence.RegionID select r).First(); // get list of Activities currently associated with this Sequence sDisp.SelectedActivities = (from sa in db.SequencesToActivities join a in db.Activities on sa.ActivityID equals a.ActivityID join d1 in db.Destinations on a.Dest1ID equals d1.DestinationID join d2 in db.Destinations on a.Dest2ID equals d2.DestinationID where sa.SequenceID == id orderby sa.Seqnr select new SequenceActivity { Seqnr = sa.Seqnr, Id = a.ActivityID, Activity = a, Reverted = sa.Reverted, Dest1 = d1, Dest2 = d2 }).ToList(); return(View(sDisp)); }
// GET: Sequences/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sequence sequence = db.Sequences.Find(id); if (sequence == null) { return(HttpNotFound()); } var sDisp = new SequenceDisp(); sDisp.CopyData(sequence); sDisp.Region = (from r in db.Regions where r.RegionID == sDisp.RegionID select r).First(); sDisp.SelectedActivities = (from sa in db.SequencesToActivities join a in db.Activities on sa.ActivityID equals a.ActivityID join d1 in db.Destinations on a.Dest1ID equals d1.DestinationID join d2 in db.Destinations on a.Dest2ID equals d2.DestinationID where sa.SequenceID == id orderby sa.Seqnr select new SequenceActivity { Seqnr = sa.Seqnr, Id = a.ActivityID, Activity = a, Reverted = sa.Reverted, Dest1 = d1, Dest2 = d2 }).ToList(); if (sDisp.SelectedActivities.Count() > 0) { SequenceActivity sa = sDisp.SelectedActivities[sDisp.SelectedActivities.Count() - 1]; int dID = (sa.Reverted ? sa.Dest1.DestinationID : sa.Dest2.DestinationID); // limit Activities to those that start where the last one ended sDisp.AvailableActivities = (from a in db.Activities join d1 in db.Destinations on a.Dest1ID equals d1.DestinationID join d2 in db.Destinations on a.Dest2ID equals d2.DestinationID where d1.RegionID == sequence.RegionID & (a.Dest1ID == dID | a.Dest2ID == dID) orderby a.ExperienceRating descending select new SequenceActivity { Seqnr = 0, Id = a.ActivityID, Activity = a, Reverted = false, Dest1 = d1, Dest2 = d2 }).ToList(); } else { sDisp.AvailableActivities = (from a in db.Activities join d1 in db.Destinations on a.Dest1ID equals d1.DestinationID join d2 in db.Destinations on a.Dest2ID equals d2.DestinationID where d1.RegionID == sequence.RegionID orderby a.ExperienceRating descending select new SequenceActivity { Seqnr = 0, Id = a.ActivityID, Activity = a, Reverted = false, Dest1 = d1, Dest2 = d2 }).ToList(); } ViewBag.RegionID = new SelectList(db.Regions, "RegionID", "Name", sequence.RegionID); return(View(sDisp)); }