public async Task<IHttpActionResult> AddCourseToCourseCategory(CoursesInCourseCategory coursesInCourseCategory) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } this.db.CoursesInCourseCategories.Add(coursesInCourseCategory); try { this.db.SaveChanges(); } catch (DbUpdateException) { if (this.CoursesInCourseCategoryExists(coursesInCourseCategory.CourseCategoryId)) { return this.Conflict(); } throw; } return this.Ok(coursesInCourseCategory); }
public async Task<IHttpActionResult> DeleteCourseInCourseCategory(CoursesInCourseCategory model) { CoursesInCourseCategory coursesInCourseCategory = this.db.CoursesInCourseCategories.First(c => c.CourseId == model.CourseId && c.CourseCategoryId == model.CourseCategoryId); if (coursesInCourseCategory == null) { return this.NotFound(); } this.db.CoursesInCourseCategories.Remove(coursesInCourseCategory); this.db.SaveChanges(); // now delete course too var resource = new CoursesController(); if (await resource.DeleteCourse(model.CourseId) == this.NotFound()) { return this.NotFound(); } // TODO: delete all course content for this course return this.Ok(coursesInCourseCategory); }