コード例 #1
0
        public ActionResult Edit(KarateStudent karateStudent, int[] selectedCoaches)
        {
            KarateStudent newStudent = db.KarateStudents.Find(karateStudent.Id);

            newStudent.Name            = karateStudent.Name;
            newStudent.LastName        = karateStudent.LastName;
            newStudent.Age             = karateStudent.Age;
            newStudent.Country         = karateStudent.Country;
            newStudent.City            = karateStudent.City;
            newStudent.Belt            = karateStudent.Belt;
            newStudent.CountCoach      = karateStudent.CountPeople(selectedCoaches);
            newStudent.YearsTraining   = karateStudent.YearsTraining;
            newStudent.SportsmanStatus = karateStudent.SportsmanStatus;
            newStudent.LikeCompetition = karateStudent.LikeCompetition;
            newStudent.TeamId          = karateStudent.TeamId;
            newStudent.Coaches.Clear();
            if (selectedCoaches != null)
            {
                foreach (var c in db.Coaches.Where(co => selectedCoaches.Contains(co.Id)))
                {
                    newStudent.Coaches.Add(c);
                }
            }
            db.Entry(newStudent).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("ShowStudents", "Student"));
        }
コード例 #2
0
        public ActionResult Create(KarateStudent karateStudent, int[] selectedCoaches)
        {
            if (selectedCoaches != null)
            {
                foreach (var c in db.Coaches.Where(co => selectedCoaches.Contains(co.Id)))
                {
                    karateStudent.Coaches.Add(c);
                }
            }
            karateStudent.CountCoach = karateStudent.CountPeople(selectedCoaches);

            db.KarateStudents.Add(karateStudent);
            db.SaveChanges();
            return(RedirectToAction("ShowStudents", "Student"));
        }