Ejemplo n.º 1
0
        public async Task <IActionResult> Insert(CreateBlogDTO blogcreate)
        {
            Blog blog = await _mediator.Send(new CreateBlogCommand
            {
                createblog = blogcreate
            });

            return(CreatedAtAction(nameof(GetById), new { id = blog.Id }, blog));
        }
Ejemplo n.º 2
0
        public async Task <MessageModel <ResultBlogDTO> > Post([FromBody] CreateBlogDTO blog)
        {
            var model = _mapper.Map <Blog>(blog);

            blog.Tag.ForEach(t => {
                model.Blog_Tags.Add(new Blog_Tag()
                {
                    Tag = new Tag()
                    {
                        Name = t.Trim(),
                    },
                    //Blog = model
                });
            });


            //model.Blog_Tags.ForEach(bt =>
            //{
            //    bt.Tag.Blog_Tags.Add(bt);
            //});


            var ca = await _service.Add(model);

            var result = _mapper.Map <ResultBlogDTO>(model);

            model.Blog_Tags.ForEach(t =>
            {
                result.Tags.Add(t.Tag);
            });

            return(new MessageModel <ResultBlogDTO>()
            {
                msg = "成功",
                response = result
            });
        }