예제 #1
0
        public ActionResult Edit([Bind(Include = "Id,Code,Name,Description")] Course course, string[] selectedFaculties)
        {
            if (selectedFaculties != null)
            {
                if (ModelState.IsValid)
                {
                    _db.Entry(course).State = EntityState.Modified;
                    UpdateFaculties(course, selectedFaculties, _db);
                    _db.SaveChanges();
                    return(RedirectToAction("Edit", new { id = course.Id }));
                }
            }
            else
            {
                _errors.Add("Please select at least one faculty before update.");
                TempData["errors"] = _errors;
            }

            var fcm       = new FacultyCourseModel();
            var faculties = _db.Faculties.ToList();

            fcm.Faculties    = faculties;
            course.Faculties = _db.Faculties.Where(f => f.Courses.Any(c => c.Id == course.Id)).ToList();
            fcm.Course       = course;
            return(View(fcm));
        }
예제 #2
0
        public ActionResult Create([Bind(Include = "Id,Code,Name,Description")] Course course, string[] selectedFaculties)
        {
            if (selectedFaculties != null)
            {
                if (ModelState.IsValid)
                {
                    _db.Courses.Add(course);
                    UpdateFaculties(course, selectedFaculties, _db);
                    _db.SaveChanges();
                    return(RedirectToAction("Details", new { id = course.Id }));
                }
            }
            else
            {
                _errors.Add("Please select at least one faculty before create.");
                TempData["errors"] = _errors;
            }

            var fcm       = new FacultyCourseModel();
            var faculties = _db.Faculties.ToList();

            fcm.Faculties = faculties;
            fcm.Course    = new Course();

            return(View(fcm));
        }
예제 #3
0
        public ActionResult Create()
        {
            var fcm       = new FacultyCourseModel();
            var faculties = _db.Faculties.ToList();

            fcm.Faculties = faculties;
            fcm.Course    = new Course();
            return(View(fcm));
        }
예제 #4
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var fcm       = new FacultyCourseModel();
            var faculties = _db.Faculties.ToList();

            fcm.Faculties = faculties;

            var course = _db.Courses.Find(id);

            if (course == null)
            {
                return(HttpNotFound());
            }
            fcm.Course = course;
            return(View(fcm));
        }