public ActionResult <MessageDto> CreateMessage(MessageForCreationDto message) { var messageEntity = _mapper.Map <Entities.Message>(message); _messageBoardRepository.AddMessage(messageEntity); _messageBoardRepository.Save(); var messageToReturn = _mapper.Map <MessageDto>(messageEntity); return(CreatedAtRoute("GetMessage", new { messageId = messageToReturn.Id }, messageToReturn)); }
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 HttpResponseMessage Post(int topicId, [FromBody] Reply newReply) { if (newReply.Created == default(DateTime)) { newReply.Created = DateTime.UtcNow; } newReply.TopicId = topicId; if (_repo.AddReply(newReply) && _repo.Save()) { return(Request.CreateResponse(HttpStatusCode.Created, newReply)); } 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 IHttpActionResult Post(int topicId, [FromBody] Reply newReply) { if (newReply.Created == default(DateTime)) { newReply.Created = DateTime.UtcNow; } newReply.TopicId = topicId; if (_repo.AddReply(newReply) && _repo.Save()) { return(this.CreatedAtRoute("ReplyRoute", new { topicId = newReply.TopicId, id = newReply.Id }, newReply)); } return(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)); } }
public HttpResponseMessage Post(int topicId, [FromBody] Reply reply) { if (reply.Created == default(DateTime)) { reply.Created = DateTime.Now; } reply.TopicId = topicId; if (_messageBoardRepository.AddReply(reply) && _messageBoardRepository.Save()) { return(Request.CreateResponse(HttpStatusCode.Created, reply)); } return(Request.CreateResponse(HttpStatusCode.BadRequest)); }
public IHttpActionResult Post(int topicId, [FromBody] Reply reply) { var topic = _repo.GetTopics().FirstOrDefault(t => t.Id == topicId); if (topic == null) { return(BadRequest()); } else { reply.Created = DateTime.Now; reply.TopicId = topicId; if (_repo.AddReply(reply) && _repo.Save()) { return(CreatedAtRoute("replies", new { id = reply.Id }, reply)); } else { return(BadRequest()); } } }