public async Task <IActionResult> Create([FromBody] CoursePostViewModel course)
        {
            var courseForSave = _mapper.Map <CoursePostViewModel, Course>(course);


            courseForSave.Author = await _userManager.GetUserAsync(HttpContext.User);

            _courseData.AddCourse(courseForSave);

            var courseFromDb = _courseData.GetCourseByName(course.Name);

            var category = _courseData.GetCategories().FirstOrDefault(c => c.Name.ToLower() == course.Category.ToLower());

            if (category == null)
            {
                category = new Category
                {
                    Name = course.Category
                };
                _courseData.AddCategory(category);
            }
            _courseData.AddCategoryToCourse(category, courseFromDb);
            _courseData.UpdateCourse(courseFromDb);
            return(Json(new { result = "Redirect", url = Url.Action("UploadContent", "Course", new { id = courseFromDb.Id }) }));
        }
예제 #2
0
        public IActionResult CreateCourse(CourseDto courseDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var course = _mapper.Map <CourseDto, Course>(courseDto);

            _data.AddCourse(course);
            return(Created(new Uri(Request.GetDisplayUrl() + "/" + course.Id), courseDto));
        }