예제 #1
0
        public HttpResponseMessage PostArticle(Article item)
        {
            item.CreatedOn = DateTime.Now;
            item.LastModified = DateTime.Now;
            item = repository.Add(item);
            var response = Request.CreateResponse<Article>(HttpStatusCode.Created, item);

            string uri = Url.Link("DefaultApi", new { id = item.Id });
            response.Headers.Location = new Uri(uri);
            return response;
        }
예제 #2
0
 public Article Add(Article item)
 {
     db.Articles.Add(item);
     db.SaveChanges();
     return item;
 }
예제 #3
0
 public bool Update(Article item)
 {
     try
     {
         db.Entry(item).State = EntityState.Modified;
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #4
0
 public void PutArticle(int id, Article item)
 {
     item.Id = id;
     item.LastModified = DateTime.Now;
     if (!repository.Update(item))
     {
         throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
     }
 }