Пример #1
0
 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"
         }));
     }
 }
Пример #2
0
        // 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"
                }));
            }
        }
Пример #3
0
 public void Update(T t)
 {
     _dataContext.Entry(t).State = EntityState.Modified;
 }