Beispiel #1
0
        // PUT api/Blog/5
        public HttpResponseMessage PutBlogEntry(int id, BlogEntry blogentry)
        {
            if (ModelState.IsValid && id == blogentry.Id)
            {
                db.Entry(blogentry).State = EntityState.Modified;

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

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Beispiel #2
0
        // POST api/Blog
        public HttpResponseMessage PostBlogEntry(BlogEntry blogentry)
        {
            if (ModelState.IsValid)
            {
                db.BlogEntries.Add(blogentry);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, blogentry);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = blogentry.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }