Example #1
0
        // POST api/Events
        public HttpResponseMessage PostEvent(Event digEvent)
        {
            if (ModelState.IsValid)
            {
                db.Events.Add(digEvent);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, digEvent);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = digEvent.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Example #2
0
        // PUT api/Events/5
        public HttpResponseMessage PutEvent(int id, Event digEvent)
        {
            if (ModelState.IsValid && id == digEvent.Id)
            {
                db.Entry(digEvent).State = EntityState.Modified;

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

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