// DELETE api/timeslots/2 public HttpResponseMessage Delete(int id) { var timeSlot = new TimeSlot { TimeSlotId = id }; _db.TimeSlots.Attach(timeSlot); var status = _db.TimeSlots.Remove(timeSlot); _db.SaveChanges(); if (status != null) return new HttpResponseMessage(HttpStatusCode.OK); throw new HttpResponseException(HttpStatusCode.NotFound); }
//POST api/timeslots public HttpResponseMessage Post([FromBody]TimeSlotModel values) { var timeSlot = new TimeSlot { Start = values.TimeSlotStartTime, Duration = values.TimeSlotDuration }; var ts = _db.TimeSlots.Add(timeSlot); _db.SaveChanges(); if(ts!=null) { var msg = new HttpResponseMessage(HttpStatusCode.Created); msg.Headers.Location = new Uri(Request.RequestUri + "/" + timeSlot.TimeSlotId.ToString()); return msg; } else { var msg = new HttpResponseMessage(HttpStatusCode.BadRequest); return msg; } }