コード例 #1
0
 public HttpResponseMessage Post([FromBody] Topic newTopic)
 {
     if (newTopic.Created == default(DateTime))
     {
         newTopic.Created = DateTime.UtcNow;
     }
     if (_repo.AddTopic(newTopic) && _repo.Save())
     {
         return(Request.CreateResponse(HttpStatusCode.Created, newTopic));
     }
     return(Request.CreateResponse(HttpStatusCode.BadRequest));
 }
コード例 #2
0
        public IHttpActionResult Post([FromBody] Topic topic)
        {
            topic.Created = DateTime.Now;

            if (_repo.AddTopic(topic) && _repo.Save())
            {
                return(CreatedAtRoute("topics", new { id = topic.Id }, topic));
            }
            else
            {
                return(BadRequest());
            }
        }
コード例 #3
0
        //notice WebApi doesn't require the HttpPost attribute bcz the method name is Post
        public HttpResponseMessage Post([FromBody] Topic newTopic)  //FromBody is not required but is a good practice to ensure body is injected
        {
            if (newTopic.Created == default(DateTime))
            {
                newTopic.Created = DateTime.UtcNow;
            }
            if (_repo.AddTopic(newTopic) &&
                _repo.Save())
            {
                return(Request.CreateResponse(HttpStatusCode.Created, newTopic));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
コード例 #4
0
        public IHttpActionResult Post([FromBody] Topic newTopic)
        {
            if (newTopic.Created == default(DateTime))
            {
                newTopic.Created = DateTime.UtcNow;
            }

            if (_repo.AddTopic(newTopic) &&
                _repo.Save())
            {
                return(CreatedAtRoute("DefaultApi", new { id = newTopic.Id }, newTopic));
            }

            return(BadRequest("Couldn't save the topic"));
        }
コード例 #5
0
        public HttpResponseMessage Post([FromBody] Topic topic)
        {
            if (topic.Created == default(DateTime))
            {
                topic.Created = DateTime.Now;
            }

            if (_messageBoardRepository.AddTopic(topic) &&
                _messageBoardRepository.Save())
            {
                return(Request.CreateResponse(HttpStatusCode.Created, topic));
            }

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
コード例 #6
0
        public HttpResponseMessage Post([FromBody] Topic topic)
        {
            if (topic.Created == default(DateTime))
            {
                topic.Created = DateTime.Now;
            }

            if ((_repo.AddTopic(topic)) &&
                _repo.Save())
            {
                return(Request.CreateResponse(HttpStatusCode.Created, topic));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
        }