public ActionResult Generate(int startSlotID)
{
var currentEvent = db.Events.Find(eventID);
TimeSlot startSlot = db.TimeSlots.Find(startSlotID);
IEnumerable<Activity> schedule;
IEnumerator<Activity> scheduleEnumerator;
IEnumerable<Group> groupData =
from item in db.Groups.Include(g => g.Type) // Preloading GroupType so that it isn't lazy loaded in the GreedyScheduler.
where item.Event.ID == eventID
select item;
IEnumerable<Station> stationData =
from item in db.Stations.Include(s => s.AvailableTimeSlots) // Workaround for not having MultipleActiveResultSets on AppHarbor
// since the GreedyScheduler was lazy loading AvailableTimeSlots
// after the DB had already been queried to clear the old schedule
where item.Event.ID == eventID
select item;
IEnumerable<TimeSlot> timeslotData =
from item in db.TimeSlots
where item.Event.ID == eventID
orderby item.Start ascending
select item;
IEnumerable<TimeSlot> generalSlots =
from item in db.TimeSlots
where item.Event.ID == eventID && item.isGeneral
orderby item.Start ascending
select item;
IEnumerable<SchedulingConstraint> constraintData =
from item in db.SchedulingConstraints.Include(c => c.Group).Include(c => c.GroupType).Include(c => c.Station)
where item.Event.ID == eventID
select item;
IEnumerable<Activity> activityData =
from item in db.Activities
where item.Event.ID == eventID
select item;
ClearSchedule();
// call algorithm to generate schedule
schedule = Boy_Scouts_Scheduler.Algorithm.Scheduler.Schedule(groupData.ToList(), stationData, constraintData, timeslotData, activityData, startSlot);
scheduleEnumerator = schedule.GetEnumerator();
while (scheduleEnumerator.MoveNext())
{
db.Activities.Add(new Activity
{
Event = currentEvent,
Group = scheduleEnumerator.Current.Group,
TimeSlot = scheduleEnumerator.Current.TimeSlot,
Station = scheduleEnumerator.Current.Station
});
db.SaveChanges();
}
return RedirectToAction("Index");
}