示例#1
0
        public ActionResult CreateCourse(CourseViewModel course)
        {
            if (ModelState.IsValid)
            {
                var duration = course.EndDate - course.StartDate;
                _courseRepository.Create(new Course
                {
                    Duration  = duration.Days,
                    StartDate = course.StartDate,
                    Theme     = course.Theme,
                    Title     = course.Title,
                });
                if (course.LecturerName != null)
                {
                    _courseRepository.AddLecturerToCourse(course.LecturerName,
                                                          _courseRepository.GetAll().Last().CourseId);
                }
                _logger.Info("Method CreateCourse(Post). The course was created success");

                return(RedirectToAction("Index"));
            }

            var users = UserManager.Users.OfType <Domain.Core.Lecturer>();

            ViewBag.Lecturers = new SelectList(users, "UserName", "UserName");
            return(View(course));
        }