public ActionResult Create(Course course, FormCollection collection)
        {
            if (ModelState.IsValid)
            {
                course.course_id = course.dept_id + course.course_no;
                course.gfr = (collection["Course.gfr"] ?? "0").Split(',').Sum(x => Int32.Parse(x));
                course.gep = (collection["Course.gep"] ?? "0").Split(',').Sum(x => Int32.Parse(x));
                courseDB.AddToCourses(course);
                courseDB.SaveChanges();

                return RedirectToAction("Index");
            }

            // Invalid – redisplay with errors
            var viewModel = new CourseManagerViewModel
            {
                Course = course,
                Departments = courseDB.Departments.ToList(),
                GFRs = courseDB.GFRs.ToList(),
                GEPs = courseDB.GEPs.ToList()
            };

            return View(viewModel);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Create a new Course object.
 /// </summary>
 /// <param name="course_id">Initial value of the course_id property.</param>
 /// <param name="dept_id">Initial value of the dept_id property.</param>
 public static Course CreateCourse(global::System.String course_id, global::System.String dept_id)
 {
     Course course = new Course();
     course.course_id = course_id;
     course.dept_id = dept_id;
     return course;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Courses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCourses(Course course)
 {
     base.AddObject("Courses", course);
 }