示例#1
0
        public IHttpActionResult UpdatePost(string postId, [FromBody] APIEditedPostModel editedPostModel)
        {
            object jsonObject;

            if (!ModelState.IsValid)
            {
                jsonObject = new { status = 500 };
                return(Json(jsonObject));
            }

            PostDTO postDTO = dataMapper.MapEditedPostModelToDTO(editedPostModel);

            postDTO.PostId = postId;

            if (string.IsNullOrWhiteSpace(postDTO.ThumbnailImageSrc))
            {
                postDTO.ThumbnailImageSrc = APISettings.EMPTY_IMAGE;
            }

            bool updateSuccessfully = postService.Update(postDTO);

            if (!updateSuccessfully)
            {
                jsonObject = new { status = 500 };
            }
            else
            {
                jsonObject = new { status = 200 };
            }

            return(Json(jsonObject));
        }
示例#2
0
        public IHttpActionResult GetEditedPost(string postId)
        {
            object  jsonObject;
            PostDTO postDTO = postService.GetPost(postId);

            if (postDTO == null)
            {
                jsonObject = new { status = 500 };
            }
            else
            {
                APIEditedPostModel editedPostModel = dataMapper.MapEditedPostDTOToModel(postDTO);

                jsonObject = new
                {
                    status = 200,
                    data   = editedPostModel
                };
            }

            return(Json(jsonObject));
        }