Esempio n. 1
0
        public HttpResponseMessage Post([FromBody] Topic newTopic)
        {
            if (newTopic.Created == default(DateTime))
            {
                newTopic.Created = DateTime.UtcNow;
            }

            if (User.Identity.Name != null)
            {
                newTopic.UserName = User.Identity.Name;
            }
            else
            {
                newTopic.UserName = "******";
            }

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

            return(Request.CreateResponse(HttpStatusCode.BadRequest));
        }
Esempio n. 2
0
        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));
        }