public HttpResponseMessage Put(Topic topic) { using (var db = new TopicsDataContext()) { db.Topics.Attach(topic); db.Entry(topic).State = EntityState.Modified; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, new { message = "topic is updated successfully" })); } }
// DELETE api/topic/2 public HttpResponseMessage Delete(int id) { using (var db = new TopicsDataContext()) { var topic = db.Topics.SingleOrDefault(t => t.Id == id); if (topic == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, new { message = "The topic you want to delete was not found" })); } db.Topics.Attach(topic); db.Entry(topic).State = EntityState.Deleted; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, new { message = "The topic was deleted successfully" })); } }
public void Update(T t) { _dataContext.Entry(t).State = EntityState.Modified; }