示例#1
0
        public async Task <IActionResult> Post(PostDto postDto)
        {
            //Convertir Dto a entidad de Dominio
            //Mapear
            //var post = new Post
            //{
            //    Date = postDto.Date,
            //    Image = postDto.Image,
            //    UserId = postDto.UserId
            //};

            //if (!ModelState.IsValid)
            //{
            //    return BadRequest(ModelState);
            //}
            //AutoMapper
            var post = _mapper.Map <Post>(postDto);

            await postServices.InsertPost(post);

            postDto = _mapper.Map <PostDto>(post);
            var response = new ApiResponse <PostDto>(postDto);

            return(Ok(response));
        }