Exemplo n.º 1
0
        /// <summary>
        /// Updates the specified blog post
        /// </summary>
        /// <param name="blogPostChanges"></param>
        /// <returns></returns>
        public BlogPost PutBlog(BlogPost blogPostChanges)
        {
            if (_blogManager.CheckSlug(blogPostChanges.slug))
            {
                throw new KeyNotFoundException("The blog post specified by the url does not exist");
            }
            //Check if any change was made
            if (blogPostChanges.title == null && blogPostChanges.taglist == null && blogPostChanges.description == null && blogPostChanges.body == null)
            {
                throw new InvalidOperationException("No changes to the Blog Post were made.");
            }
            //GetOldBlogPost
            BlogPost oldBlogPost = _blogManager.GetBlogPost(blogPostChanges.slug);

            //If title changed
            if (blogPostChanges.title != null)
            {
                _blogManager.DeletePost(oldBlogPost.slug);
                //create new slug
                string newSlug = _slugfyHelper.SlugifyTheTitle(blogPostChanges.title);
                if (!_blogManager.CheckSlug(newSlug))
                {
                    newSlug = _slugfyHelper.GenerateSlugAddon(newSlug);
                }
                oldBlogPost.slug = newSlug;
            }
            //If taglist is changed
            if (blogPostChanges.taglist != null)
            {
                TagList tagList = new TagList();
                tagList.tagList = blogPostChanges.taglist;
                if (!_blogManager.ValidateTags(tagList))
                {
                    throw new ArgumentOutOfRangeException("One or more of the tags listed do not appear in the database.");
                }
                oldBlogPost.taglist = tagList.tagList;
            }
            //If description changes
            if (blogPostChanges.description != null)
            {
                oldBlogPost.description = blogPostChanges.description;
            }
            //If body changes
            if (blogPostChanges.body != null)
            {
                oldBlogPost.body = blogPostChanges.body;
            }

            oldBlogPost.updatedat = _currentTime.CurrentUTCTime();

            return(_blogManager.UpdateBlogPost(oldBlogPost));
        }
Exemplo n.º 2
0
        public bool Delete(int postId)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    return(_blogManager.DeletePost(postId));
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"Error editing post.", null);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
 public Task <bool> Delete(int postId)
 {
     return(Task.FromResult(_blogManager.DeletePost(postId)));
 }