public async Task <IHttpActionResult> PostApprovedCourse(ApprovedCourse approvedCourse) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.approvedCourses.Add(approvedCourse); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ApprovedCourseExists(approvedCourse.id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = approvedCourse.id }, approvedCourse)); }
public async Task <IHttpActionResult> PutApprovedCourse(string id, ApprovedCourse approvedCourse) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != approvedCourse.id) { return(BadRequest()); } db.Entry(approvedCourse).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ApprovedCourseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> DeleteApprovedCourse(string id) { ApprovedCourse approvedCourse = await db.approvedCourses.FindAsync(id); if (approvedCourse == null) { return(NotFound()); } db.approvedCourses.Remove(approvedCourse); await db.SaveChangesAsync(); return(Ok(approvedCourse)); }
public async Task <IHttpActionResult> GetApprovedCourse(string id) { ApprovedCourse approvedCourse = await db.approvedCourses.FindAsync(id); if (approvedCourse == null) { return(NotFound()); } return(Ok(new { approvedCourse.id, approvedCourse.name })); }