public ActionResult Edit([Bind(Include = "TrainingID,Name,TrainingDate,Location,TrainingEnd,NumberOfMeetings,Duration,ExpireDate,ExpirationDate,QualificationID")] Training training, int[] subsectors)
        {
            if (ModelState.IsValid)
            {
                db.Entry(training).State = EntityState.Modified;
                // training.TrainingSubSectors.Clear();

                var SubSectorToTrainingList = db.TrainingSubSectors.Where(t => t.TrainingID == training.TrainingID).ToList();

                foreach (var train in SubSectorToTrainingList)
                {
                    db.TrainingSubSectors.Remove(train);
                }

                foreach (var id in subsectors)
                {
                    SubSector sub = db.SubSectors.Find(id);
                    training.AddSubSector(sub);
                }
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var sectorlist = (from s in training.TrainingSubSectors
                              select s.SubSector.SectorID).ToArray();

            var subsectorlist = (from s in training.TrainingSubSectors
                                 select s.SubSectorID).ToArray();

            ViewBag.Sectors         = new MultiSelectList(db.Sectors, "SectorID", "SectorType", sectorlist);
            ViewBag.subSectors      = new MultiSelectList(db.SubSectors, "SubSectorID", "SubSectortype", subsectorlist);
            ViewBag.QualificationID = new MultiSelectList(db.Qualification, "QualificationID", "Name");

            return(View(training));
        }
        public ActionResult Create([Bind(Include = "TrainingID,Name,TrainingDate,Location,TrainingEnd,NumberOfMeetings,Duration,ExpireDate,ExpirationDate,QualificationID")] Training training, int[] subsectors)
        {
            if (ModelState.IsValid)
            {
                foreach (var id in subsectors)
                {
                    SubSector subsector = db.SubSectors.Find(id);
                    training.AddSubSector(subsector);
                }

                db.Trainings.Add(training);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }


            ViewBag.Sectors         = new MultiSelectList(db.Sectors, "SectorID", "SectorType");
            ViewBag.subSectors      = new MultiSelectList(db.SubSectors, "SubSectorID", "SubSectortype");
            ViewBag.QualificationID = new SelectList(db.Qualification, "QualificationID", "Name");
            return(View(training));
        }