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));
 }
Exemple #2
0
        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(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));
        }
Exemple #4
0
        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());
                }
            }
        }