Beispiel #1
0
        // GET api/universities/{universityCode}/programs/{programCode}
        public EIProgram GetProgram(string universityCode, string programCode)
        {
            EIProgram program = db.Programs.SingleOrDefault(p => p.EducationalInstitute.Code == universityCode && p.Code == programCode);

            if (program == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(program);
        }
Beispiel #2
0
        // POST api/universities/{universityCode}/programs/
        public HttpResponseMessage PostProgram(string universityCode, EIProgram program)
        {
            if (ModelState.IsValid)
            {
                program.EducationalInstitute = db.EducationalInstitutes.Single(u => u.Code == universityCode);
                db.Programs.Add(program);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, program);
                response.Headers.Location = new Uri(Url.Link("ProgramsOfEducationalInstitute", new { universityCode = universityCode, programCode = program.Code }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Beispiel #3
0
        // DELETE api/universities/{universityCode}/programs/{programCode}
        public HttpResponseMessage DeleteProgram(string universityCode, string programCode)
        {
            EIProgram program = GetProgram(universityCode, programCode);

            if (program == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            db.Programs.Remove(program);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, program));
        }
Beispiel #4
0
        // PUT api/universities/{universityCode}/programs/{programCode}
        public HttpResponseMessage PutProgram(string universityCode, EIProgram program)
        {
            if (ModelState.IsValid)
            {
                program.EducationalInstitute = db.EducationalInstitutes.Single(u => u.Code == universityCode);
                db.Entry(program).State      = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound));
                }

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }