public HttpResponseMessage DeleteSchoolStudents(int schoolid, [FromUri] int studentid) { if (studentid == null) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest); return response; } else { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); if (service.DeleteSchoolStudent(schoolid, studentid)) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NoContent); return response; } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NotFound); return response; } } } }
public SchoolDTO GetSchool(int schoolid) { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); SchoolDTO school = service.GetSchool(schoolid); if (school == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } // this should still return the proper response headers // even without specifically returning an HttpResponseMessage object return school; } }
public HttpResponseMessage Delete(int schoolid) { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); if (service.DeleteSchool(schoolid)) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NoContent); return response; } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.NotFound); return response; } } }
public HttpResponseMessage PostSchoolStudents(int schoolid, [FromBody] Models.StudentID studentid) { if (ModelState.IsValid) { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); SchoolStudentDTO SchoolStudent = service.CreateSchoolStudent(schoolid, studentid.studentid); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, SchoolStudent); return response; } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public HttpResponseMessage PostSchool(School school) { if (ModelState.IsValid) { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); SchoolDTO schoolDTO = service.CreateSchool(school); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, schoolDTO); return response; } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public List<StudentDTO> GetSchoolStudents(int schoolid) { using (provider = new EntDAL.EFProvider()) { SchoolService service = new SchoolService(provider); List<StudentDTO> students = service.GetSchoolStudents(schoolid); return students; } }
public HttpResponseMessage GetSchools() { // My original idea was to create 2 different data access layers (one with entity framework and one with nHibernate), // then let you use a Header value to determine which DAL to use and inject the chosen provider into the service. using (provider = new EntDAL.EFProvider()) { // create service with ORM injection SchoolService service = new SchoolService(provider); // get the list of schools List<SchoolDTO> schools = service.GetSchools(); // return the response HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, schools, "application/json"); return response; } }