Ejemplo n.º 1
0
        public string CreateSlugFromPostTitle(string title)
        {
            var baseSlug    = title.GenerateSlug();
            var currentSlug = baseSlug;

            var postWithSlug = _dataProvider.GetPostBySlug(currentSlug);

            var i = 1;

            while (postWithSlug != null)
            {
                currentSlug  = $"{baseSlug}-{i}";
                postWithSlug = _dataProvider.GetPostBySlug(currentSlug);
                i++;
            }

            return(currentSlug);
        }
Ejemplo n.º 2
0
        public PostViewModel GetPostBySlug(string slug)
        {
            var post = _dataProvider.GetPostBySlug(slug);

            if (post == null)
            {
                return(null);
            }

            return(_mapper.Map <PostViewModel>(post));
        }