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)); }
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()); } }
//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)); }
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")); }
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)); }
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)); } }