Пример #1
0
 //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;
     //...
 }
Пример #2
0
 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;
 }
Пример #3
0
 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;
 }
Пример #4
0
        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;
        }
Пример #5
0
        //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;
        }
Пример #6
0
 public void Create(Post post)
 {
     post.Id = _posts.Count() + 1;
     _posts.Add(post);
 }