//public HttpResponseMessage Post([ModelBinder(typeof(UserModelBinder))] User username) //public HttpResponseMessage Post([FromBody] String username) //public HttpResponseMessage Post([ValueProvider(typeof(HeaderValueFactory))] String username) public HttpResponseMessage Post(Post post, [FromUri]User user) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent("aaa"); return response; //... }
public void Update(Post post) { Post oldPost = _posts.Single(p => p.Id == post.Id); oldPost.Title = post.Title; oldPost.Date = post.Date; oldPost.Body = post.Body; }
public HttpResponseMessage Put(int id, Post post) { post.Id = id; _repository.Update(post); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, post); string uri = Url.Link("DefaultApi", new { id = post.Id }); response.Headers.Location = new Uri(uri); return response; }
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { Post model = new Post(); string key = bindingContext.ModelName; ValueProviderResult val = bindingContext.ValueProvider.GetValue(key); bindingContext.Model = model; return true; }
//public HttpResponseMessage Post([ModelBinder(typeof(UserModelBinder))]Post post) public HttpResponseMessage Post(Post post) { _repository.Create(post); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); response.StatusCode = HttpStatusCode.Created; string uri = Url.Link("DefaultApi", new { id = post.Id }); response.Headers.Location = new Uri(uri); return response; }
public void Create(Post post) { post.Id = _posts.Count() + 1; _posts.Add(post); }