Ejemplo n.º 1
0
        // GET api/UniversalCourse/5
        public UniversalCourse GetUniversalCourse(string code)
        {
            UniversalCourse universalcourse = db.UniversalCourses.Where(uc => uc.Code == code).FirstOrDefault();

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

            return(universalcourse);
        }
Ejemplo n.º 2
0
        // POST api/UniversalCourse
        public HttpResponseMessage PostUniversalCourse(UniversalCourse universalcourse)
        {
            if (ModelState.IsValid)
            {
                db.UniversalCourses.Add(universalcourse);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, universalcourse);
                response.Headers.Location = new Uri(Url.Link("UniversalCourses", new { code = universalcourse.Code }));
                return(response);
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }
Ejemplo n.º 3
0
        // DELETE api/UniversalCourse/5
        public HttpResponseMessage DeleteUniversalCourse(string code)
        {
            UniversalCourse universalcourse = db.UniversalCourses.Find(code);

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

            db.UniversalCourses.Remove(universalcourse);

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

            return(Request.CreateResponse(HttpStatusCode.OK, universalcourse));
        }
Ejemplo n.º 4
0
        // PUT api/UniversalCourse/5
        public HttpResponseMessage PutUniversalCourse(string code, UniversalCourse universalcourse)
        {
            if (ModelState.IsValid && code == universalcourse.Code)
            {
                db.Entry(universalcourse).State = EntityState.Modified;

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

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