Пример #1
0
        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;
                    }
                }
            }
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        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;
                }
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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);
            }
        }
Пример #6
0
        public List<StudentDTO> GetSchoolStudents(int schoolid)
        {
            using (provider = new EntDAL.EFProvider())
            {
                SchoolService service = new SchoolService(provider);

                List<StudentDTO> students = service.GetSchoolStudents(schoolid);

                return students;
            }
        }
Пример #7
0
        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;
            }
        }