/// <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; } }
public static PostModel ToPostModel(this BlogPostPageViewModel blogPostPageViewModel, PostEntity postEntity) { var postModel = new PostModel { Post = postEntity, DisqusEnabled = blogPostPageViewModel.DisqusEnabled }; return postModel; }
public int AddPost(PostEntity postEntity) { throw new NotImplementedException(); }
public void UpdatePost(PostEntity postEntity) { throw new NotImplementedException(); }
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"); } } }
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(); } }
private int AddPostInternal(PostEntity postEntity) { _postsTable.InsertOnSubmit(postEntity); context.SubmitChanges(); return postEntity.PostID; }
/// <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 { } }