public ActionResult Create(SchedulingConstraint schedulingconstraint)
        {
            if (ModelState.IsValid)
            {
                schedulingconstraint.Event = db.Events.Find(eventID);
                schedulingconstraint.Group = db.Groups.Find(schedulingconstraint.Group != null ? schedulingconstraint.Group.ID : -1);
                schedulingconstraint.GroupType = db.GroupTypes.Find(schedulingconstraint.GroupType != null ? schedulingconstraint.GroupType.ID : -1);
                schedulingconstraint.Station = db.Stations.Find(schedulingconstraint.Station != null ? schedulingconstraint.Station.ID : -1);
                db.SchedulingConstraints.Add(schedulingconstraint);
                db.SaveChanges();
                return PartialView("GridData", new SchedulingConstraint[] { schedulingconstraint });
            }

            return PartialEditView(schedulingconstraint);
        }
        public ActionResult Edit(SchedulingConstraint schedulingconstraint)
        {
            if (ModelState.IsValid)
            {
                SchedulingConstraint origConstraint = db.SchedulingConstraints
                    .Include(c => c.Group)
                    .Include(c => c.GroupType)
                    .Include(c => c.Station)
                    .Single(c => c.ID == schedulingconstraint.ID);
                db.Entry(origConstraint).CurrentValues.SetValues(schedulingconstraint);
                origConstraint.Group = db.Groups.Find(schedulingconstraint.Group != null ? schedulingconstraint.Group.ID : -1);
                origConstraint.GroupType = db.GroupTypes.Find(schedulingconstraint.GroupType.ID);
                origConstraint.Station = db.Stations.Find(schedulingconstraint.Station.ID);
                db.SaveChanges();
                return PartialView("GridData", new SchedulingConstraint[] { origConstraint });
            }

            return PartialEditView(schedulingconstraint);
        }
 protected PartialViewResult PartialEditView(SchedulingConstraint schedulingconstraint = null)
 {
     ViewBag.GroupTypes = db.GroupTypes.ToList();
     ViewBag.GroupTypes.Insert(0, new GroupType { ID = -1 }); // Allow null preferences
     ViewBag.Groups = db.Groups.Where(g => g.Event.ID == eventID).ToList();
     ViewBag.Groups.Insert(0, new Group { ID = -1 }); // Allow null preferences
     ViewBag.Stations = db.Stations.Where(s => s.Event.ID == eventID).ToList();
     ViewBag.Stations.Insert(0, new Station { ID = -1 }); // Allow null preferences
     return PartialView("Edit", schedulingconstraint);
 }