public IActionResult AddCourse([FromBody] AddCourseViewModel model)
        {
            var course   = _service.AddCourse(model);
            var location = Url.Link("GetCourseByID", new { id = course.ID });

            return(Created(location, course));
        }
        public IActionResult AddCourse([FromBody] CourseTemplate course)
        {
            bool retVal = _coursesService.AddCourse(course);

            if (retVal == false)
            {
                return(StatusCode(400)); // Bad request
            }

            return(Created("GetCourseById", course)); // Created 201
        }
        public IActionResult AddCourse([FromBody] CourseViewModel course)
        {
            if (course == null)
            {
                return(BadRequest());
            }
            if (!ModelState.IsValid)
            {
                return(StatusCode(412));
            }

            var newCourse = _coursesService.AddCourse(course);

            return(Ok(newCourse));
        }
Example #4
0
        public async Task <IActionResult> AddCourse(Course course)
        {
            int adminId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);

            if (await _coursesService.CourseExists(course, adminId))
            {
                return(BadRequest("The course you entered already exists!"));
            }

            _coursesService.AddCourse(course);

            if (await _genericsRepo.SaveAll())
            {
                return(NoContent());
            }

            return(BadRequest("Something went wrong!"));
        }