public async Task <IHttpActionResult> DeleteUnenroll(int enrollmentId) { try { var e = await _enrollments.Find(enrollmentId); if (e == null) { throw new NullReferenceException(); } if (User.Identity.GetUserId() != e.StudentId && !User.IsInRole("admin")) { throw new AuthenticationException(); } await _enrollments.Unenroll(enrollmentId); return(Ok()); } catch (AuthenticationException) { ModelState.AddModelError("AuthenticationException", "You don't have authority to enroll this student."); } catch (NullReferenceException) { ModelState.AddModelError("KeyNotFoundException", "Enrollment not found."); } catch (KeyNotFoundException) { ModelState.AddModelError("KeyNotFoundException", "Enrollment not found."); } catch (StudentNotEnrolledException) { ModelState.AddModelError("StudentNotEnrolledException", "Student is not yet enrolled in class."); } return(BadRequest(ModelState)); }