/// <summary> /// The add post. /// </summary> /// <param name="postEntity"> /// The post entity. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> public int AddPost(PostEntity postEntity) { int postID = -1; try { postID = this.AddPostInternal(postEntity); this.categoryService.AddCategoryMapping(postEntity.Categories, postID); if (postEntity.Tags != null) { this.tagService.AddTagsForPost(postEntity.Tags, postID); } return postID; } catch { if (postID > 0) { this.categoryService.DeleteCategoryMapping(postID); this.tagService.DeleteTagsForPost(postID); } this.DeletePost(postID); return -1; } }
/// <summary> /// The add post internal. /// </summary> /// <param name="postEntity"> /// The post entity. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private int AddPostInternal(PostEntity postEntity) { this.postTable.InsertOnSubmit(postEntity); this.Context.SubmitChanges(); return postEntity.ID; }
/// <summary> /// The update post internal. /// </summary> /// <param name="postEntity"> /// The post entity. /// </param> private void UpdatePostInternal(PostEntity postEntity) { PostEntity post = this.postTable.SingleOrDefault(p => p.ID == postEntity.ID); if (post != null) { post.Title = postEntity.Title; post.Content = postEntity.Content; post.Url = postEntity.Url; post.LastModifiedTime = postEntity.LastModifiedTime; post.CanAddComments = postEntity.CanAddComments; post.CanBeShared = postEntity.CanBeShared; post.IsPrivate = postEntity.IsPrivate; post.EntryType = postEntity.EntryType; post.Order = postEntity.Order.HasValue ? postEntity.Order.Value : (int?)null; this.Context.SubmitChanges(); } }
/// <summary> /// The update post. /// </summary> /// <param name="postEntity"> /// The post entity. /// </param> public void UpdatePost(PostEntity postEntity) { try { this.UpdatePostInternal(postEntity); this.categoryService.UpdateCategoryMapping(postEntity.Categories, postEntity.ID); if (postEntity.Tags != null) { this.tagService.UpdateTagsForPost(postEntity.Tags, postEntity.ID); } } catch { } }