Exemple #1
0
        public async Task <BlogPost> UpdateBlogPost(BlogRequest blog, Guid id)
        {
            var        updatedBlog    = blogRepository.GetById(id);
            List <Tag> updatedTagList = tagRepository.FindByCondition(x => x.BlogPostId == id);

            //List<string> tagNames = blog.TagList;


            //foreach(Tag t in updatedTagList)
            //{

            //}

            List <string> tags = blog.TagList;
            var           tag  = new Tag();

            List <Tag> list = new List <Tag>();

            foreach (String s in tags)
            {
                tag = new Tag
                {
                    TagName = s
                };
                list.Add(tag);
            }
            updatedTagList = list;

            updatedBlog.Title       = blog.Title;
            updatedBlog.Description = blog.Description;
            updatedBlog.Body        = blog.Body;
            updatedBlog.UpdatedAt   = DateTime.Now;
            updatedBlog.TagList     = updatedTagList;


            blogRepository.Update(updatedBlog);
            return(updatedBlog);
        }