Пример #1
0
        public Blog Transform(Blog blog)
        {
            _logger.LogInformation("Removing numbers from category urls...");
            foreach (var blogCategory in blog.Categories)
            {
                _logger.LogInformation($"Processing {blogCategory.Url}...");

                var newUrl = LinkUtils.MakeFriendly(blogCategory.Url);
                blogCategory.Url = newUrl;

                _logger.LogInformation($"Processed: {newUrl}");
            }

            foreach (var blogPost in blog.Posts)
            {
                _logger.LogInformation($"Processing {blogPost.Url}...");

                var newUrl = LinkUtils.MakeFriendly(blogPost.Category);
                blogPost.Category = newUrl;

                _logger.LogInformation($"Processed: {newUrl}");
            }

            _logger.LogInformation("Numbers have been removed from category urls.");
            return(blog);
        }
Пример #2
0
        public Blog Transform(Blog blogDto)
        {
            _logger.LogInformation("Transforming links...");
            foreach (var blogDtoLink in blogDto.Links)
            {
                var linkedCategory = blogDto.Categories.FirstOrDefault(_ => _.Url == blogDtoLink.Url);
                if (linkedCategory != null)
                {
                    blogDtoLink.Url = CategoryPrefix + LinkUtils.MakeFriendly(blogDtoLink.Url);
                    continue;
                }

                if (string.IsNullOrEmpty(blogDtoLink.Url))
                {
                    blogDtoLink.Url = "/";
                    continue;
                }
            }

            _logger.LogInformation("Links transformed.");

            return(blogDto);
        }