Exemplo n.º 1
0
        public ActionResult Create(vmCourse course)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (CoursesManager)
                    {
                        var item    = Mapper.Map <Course>(course);
                        var success = CoursesManager.AddCourse(item);
                        if (success)
                        {
                            return(RedirectToAction("Details", new { id = item.ID }));
                        }
                        throw new DataException("Unable to save course " + course.Title + ". Please try again.");
                    }
                }
            }
            catch (DataException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            using (DeptManager)
            {
                using (InstManager)
                {
                    using (PeopleManager)
                    {
                        using (TBManager)
                        {
                            course.Departments = DeptManager.GetAllDepartments().ToList();
                            var inst   = InstManager.GetAllInstructors();
                            var people = PeopleManager.GetAllPeople();

                            var instr = from instructor in inst
                                        join person in people on instructor.PersonID equals person.ID
                                        select new KeyValuePair <int, string>(instructor.ID, string.Format("{0}, {1}", person.LastName, person.FirstMidName));
                            course.Instructors = instr.ToDictionary(t => t.Key, t => t.Value);
                            course.Textbooks   = TBManager.GetAllTextbooks().ToList();
                        }
                    }
                }
            }
            return(View(course));
        }
Exemplo n.º 2
0
 public ActionResult AddCourse(Course course, string lector)
 {
     logManager.AddEventLog("ManageCoursesController(Admin area) => AddCourse ActionResult called(POST)", "ActionResult");
     if (ModelState.IsValid)
     {
         if (lector != null && lector != "")
         {
             course.LectorId = lector;
         }
         coursesManager.AddCourse(course);
         return(RedirectToAction("DisplayCourses", new { statusMessage = "You succesfully edited " + course.CourseName + " course!" }));
     }
     else
     {
         ModelState.AddModelError("error", "You entered invalid data!");
         ViewBag.LectorsList = new SelectList(usersManager.GetLectorsForCourseEdit(null), "Id", "LastName");
         return(View());
     }
 }