public ActionResult AddACategoryToACourse(int courseId, int categoryId) { if (courseId == null || categoryId == null) { return(BadRequest()); } var course = _courseRepository.GetCourse(courseId); var category = _categoryRepository.GetCategory(categoryId); if (course == null) { return(BadRequest()); } if (category == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_categoryRepository.AddACategoryToACourse(course, category)) { ModelState.AddModelError("", $"Something went wrong!"); return(BadRequest(ModelState)); } return(CreatedAtRoute("GetCategory", new { categoryId = category.Id }, category)); }