Esempio n. 1
0
File: Post.cs Progetto: LByron/BS
        /// <summary>
        /// Add a post. It also should take care of cateogries/tags.
        /// </summary>
        /// <param name="postEntity">The post entity.</param>
        /// <returns></returns>
        public int AddPost(PostEntity postEntity)
        {
            var postID = -1;
            try
            {
                // add the post
                postID = AddPostInternal(postEntity);

                // add the categories
                _categoryRepository.AddPostCategoryMapping(postEntity.Categories, postID);

                // add the tags
                if (postEntity.Tags != null)
                    _tagRepository.AddTagsForPost(postEntity.Tags, postID);

                // return the id
                return postID;
            }
            catch
            {
                // delete categories/tags if any
                if (postID > 0)
                {
                    _categoryRepository.DeletePostCategoryMapping(postID);
                    _tagRepository.DeleteTagsForPost(postID);
                }

                // delete the post
                DeletePost(postID);

                return -1;
            }
        }
Esempio n. 2
0
 public static PostModel ToPostModel(this BlogPostPageViewModel blogPostPageViewModel, PostEntity postEntity)
 {
     var postModel = new PostModel
         {
             Post = postEntity,
             DisqusEnabled = blogPostPageViewModel.DisqusEnabled
         };
     return postModel;
 }
Esempio n. 3
0
 public int AddPost(PostEntity postEntity)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
 public void UpdatePost(PostEntity postEntity)
 {
     throw new NotImplementedException();
 }
Esempio n. 5
0
 private void ValidateEditRequest(PostEntity postEntity)
 {
     if (postEntity.IsPrivate)
     {
         if (postEntity.OwnerUserID != GetUserId())
         {
             throw new UnauthorizedAccessException("Unauthorized attempt to edit the post");
         }
     }
     else
     {
         if (postEntity.OwnerUserID != GetUserId() && !User.IsInRole("SuperAdmin"))
         {
             throw new UnauthorizedAccessException("Unauthorized attempt to edit the post");
         }
     }
 }
Esempio n. 6
0
        private void UpdatePostInternal(PostEntity postEntity)
        {
            var post = _postsTable.SingleOrDefault(p => p.PostID == postEntity.PostID);
            if (post != null)
            {
                post.PostTitle = postEntity.PostTitle;
                post.PostContent = postEntity.PostContent;
                post.PostUrl = postEntity.PostUrl;
                post.PostEditedDate = postEntity.PostEditedDate;
                post.UserCanAddComments = postEntity.UserCanAddComments;
                post.CanBeShared = postEntity.CanBeShared;
                post.IsPrivate = postEntity.IsPrivate;
                post.EntryType = postEntity.EntryType;
                post.BitlyUrl = postEntity.BitlyUrl;
                post.BitlySourceUrl = postEntity.BitlySourceUrl;
                post.Order = postEntity.Order.HasValue ? postEntity.Order.Value : (int?)null;

                context.SubmitChanges();
            }
        }
Esempio n. 7
0
 private int AddPostInternal(PostEntity postEntity)
 {
     _postsTable.InsertOnSubmit(postEntity);
     context.SubmitChanges();
     return postEntity.PostID;
 }
Esempio n. 8
0
        /// <summary>
        /// Update a post. It also should take care of cateogries/tags.
        /// </summary>
        /// <param name="postEntity">The post entity.</param>
        public void UpdatePost(PostEntity postEntity)
        {
            try
            {
                UpdatePostInternal(postEntity);

                _categoryRepository.UpdatePostCategoryMapping(postEntity.Categories, postEntity.PostID);

                if (postEntity.Tags != null)
                    _tagRepository.UpdateTagsForPost(postEntity.Tags, postEntity.PostID);
            }
            catch
            {
                
            }
        }