コード例 #1
0
        public IActionResult Create(CreateViewModel course)
        {
            string callerId = _userManager.GetUserId(HttpContext.User);

            if (ModelState.IsValid)
            {
                CourseViewModel result;

                Course editingCourse;

                try
                {
                    if (course.Id.HasValue && (editingCourse =
                                                   _context.Courses.Include(c => c.Teachers)
                                                   .FirstOrDefault(c => c.Id == course.Id.Value)) != null)
                    {
                        result = _courseLogic.Edit(callerId, editingCourse.Id, course);
                    }
                    else
                    {
                        result = _courseLogic.Create(callerId, course);
                    }
                    return(RedirectToAction("Index", "Course"));
                }
                catch (NotFoundException)
                {
                    return(NotFound());
                }
                catch (IllegalAccessException)
                {
                    return(Challenge());
                }
            }
            return(View(course));
        }