// POST api/Attendance public HttpResponseMessage PostAttendance(Attendance attendance) { if (ModelState.IsValid) { db.Attendances.Add(attendance); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, attendance); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = attendance.Id })); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
// PUT api/Attendance public HttpResponseMessage PutAttendance(int id, Attendance attendance) { if (ModelState.IsValid) { db.Entry(attendance).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { return Request.CreateResponse(HttpStatusCode.NotFound); } return Request.CreateResponse(HttpStatusCode.OK, attendance); } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }