コード例 #1
0
        public HttpResponseMessage GetById(HttpRequestMessage request,
                                           [FromBody] PostViewModel postViewModel)
        {
            TransactionalInformation transactionalInformation;
            HttpResponseMessage      response;
            var postId  = postViewModel.ID;
            var postDto = _postBusinessService.GetPost(postId, out transactionalInformation);

            if (transactionalInformation.ReturnStatus == false)
            {
                postViewModel.ReturnStatus     = false;
                postViewModel.ReturnMessage    = transactionalInformation.ReturnMessage;
                postViewModel.ValidationErrors = transactionalInformation.ValidationErrors;

                var responseError = request.CreateResponse(HttpStatusCode.BadRequest, postViewModel);
                return(responseError);
            }
            else
            {
                postViewModel.CopyFromPostDTO(postDto);
                postViewModel.ReturnStatus  = true;
                postViewModel.ReturnMessage = transactionalInformation.ReturnMessage;
                response = request.CreateResponse(HttpStatusCode.OK, postViewModel);
            }

            return(response);
        }