Example #1
0
        public HttpResponseMessage GetReply(int replyId)
        {
            // http://localhost:49578/api/webcontent/reply?replyid=5
            var reply = BlogDbContext.Create().Replies.Find(replyId);

            if (reply == null)
            {
                ModelState.AddModelError(
                    "replyId",
                    new ArgumentException("Reply with this id is not found"));
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ModelState));
            }

            var replyBM = new ReplyBindingModel
            {
                ReplyId         = replyId,
                Text            = reply.ReplayText,
                TopicId         = reply.TopicId,
                ReplierId       = reply.UserId,
                ReplyDateString = reply.ReplayDate.ToShortDateString()
            };

            var request = Request.CreateResponse(HttpStatusCode.OK);

            request.Content = new StringContent(
                System.Web.Helpers.Json.Encode(replyBM),
                Encoding.UTF8,
                "application/json");
            return(request);
        }