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; }
public Article Add(Article item) { db.Articles.Add(item); db.SaveChanges(); return item; }
public bool Update(Article item) { try { db.Entry(item).State = EntityState.Modified; db.SaveChanges(); return true; } catch { return false; } }
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)); } }