コード例 #1
0
        private CommentDetailsResponse ToCommentDetails(Comment comment)
        {
            var poster = PersonRepository.GetById(comment.PersonId);
            var changes = CommentChangeRepository.GetForComment(comment.Id);

            return new CommentDetailsResponse
            {
                Comment = comment,
                Poster = poster,
                Changes = changes
            };
        }
コード例 #2
0
        /// <summary>
        /// Update an existing comment
        /// </summary>
        public object Put(Comment request)
        {
            var comment = CommentRepository.Update(request);

            if (comment == null)
            {
                throw HttpError.Unauthorized("Updating comment {0} failed".Fmt(request.Id));
            }

            return new HttpResult(comment)
            {
                StatusCode = HttpStatusCode.NoContent,
                Headers =
                {
                    { HttpHeaders.Location, Request.AbsoluteUri.CombineWith(comment.Id) }
                }
            };
        }
コード例 #3
0
        /// <summary>
        /// Create a new comment
        /// </summary>
        public object Post(Comment request)
        {
            var comment = CommentRepository.Add(request);

            if (comment == null)
            {
                throw HttpError.Unauthorized("Creating a new comment failed");
            }

            return new HttpResult(comment)
            {
                StatusCode = HttpStatusCode.Created,
                Headers =
                {
                    { HttpHeaders.Location, Request.AbsoluteUri.CombineWith(comment.Id) }
                }
            };
        }
コード例 #4
0
        /// <summary>
        /// Delete an existing comment
        /// </summary>
        public object Delete(Comment request)
        {
            var result = CommentRepository.Delete(request.Id);

            if (!result)
            {
                throw HttpError.Unauthorized("Deleting comment {0} failed".Fmt(request.Id));
            }

            return new HttpResult
            {
                StatusCode = HttpStatusCode.NoContent,
                Headers =
                {
                    { HttpHeaders.Location, Request.AbsoluteUri }
                }
            };
        }