/// <summary> /// Deletes the reply. /// </summary> /// <param name="reply">The reply.</param> public void DeleteReply(DiscussionReply reply) { var repository = SocialContainerProxy.Current.Resolve<DiscussionRepository>(); repository.DeleteReply(SPContext.Current.Web, reply); }
/// <summary> /// Method that updates a reply on a discussion. /// </summary> /// <param name="reply">The updated reply.</param> /// <returns> /// The updated reply object. /// </returns> public DiscussionReply UpdateReply(DiscussionReply reply) { var repository = SocialContainerProxy.Current.Resolve<DiscussionRepository>(); return repository.UpdateReply(SPContext.Current.Web, reply); }
/// <summary> /// Updates the reply. /// </summary> /// <param name="web">The web.</param> /// <param name="reply">The reply.</param> /// <returns> /// The updated discussion reply. /// </returns> public DiscussionReply UpdateReply(SPWeb web, DiscussionReply reply) { var list = this.listLocator.GetByUrl(web, this.config.DiscussionListInfo.WebRelativeUrl); var replyItem = list.GetItemById(reply.Id); if (replyItem != null) { replyItem["Body"] = reply.Body; replyItem.Update(); return this.binder.Get<DiscussionReply>(replyItem); } this.logger.Warn("DiscussionRepository.UpdateReply: Could not find reply with id '{0}'.", reply.Id); return null; }
/// <summary> /// Deletes the reply. /// </summary> /// <param name="web">The web.</param> /// <param name="reply">The reply.</param> public void DeleteReply(SPWeb web, DiscussionReply reply) { var list = this.listLocator.GetByUrl(web, this.config.DiscussionListInfo.WebRelativeUrl); var replyItem = list.GetItemById(reply.Id); if (replyItem != null) { replyItem.Delete(); } else { this.logger.Warn("DiscussionRepository.DeleteReply: Could not find item with id '{0}'.", reply.Id); } }
/// <summary> /// Replies the specified discussion. /// </summary> /// <param name="web">The web.</param> /// <param name="reply">The reply.</param> /// <returns> /// The discussion reply. /// </returns> /// <exception cref="System.ArgumentNullException">reply argument.</exception> /// <exception cref="System.InvalidOperationException">Failed to validate form digest.</exception> /// <exception cref="System.ArgumentException">Reply parent ID.</exception> public DiscussionReply Reply(SPWeb web, DiscussionReply reply) { if (reply == null) { throw new ArgumentNullException("reply"); } // Validate form digest for security if (!SPUtility.ValidateFormDigest()) { this.logger.Error("DiscussionRepository.Reply: Failed to validate form digest for reply on discussion id '{0}'.", reply.ParentFolderId); throw new InvalidOperationException("Failed to validate form digest"); } // Get discussion parent folder by ID var list = this.listLocator.GetByUrl(web, this.config.DiscussionListInfo.WebRelativeUrl); var parentFolder = list.Folders.Cast<SPListItem>().SingleOrDefault(x => x.ID == reply.ParentFolderId); if (parentFolder == null) { this.logger.Error("DiscussionRepository.Reply: The Discussion with the id '{0}' was not found", reply.ParentFolderId); throw new ArgumentException( string.Format(CultureInfo.CurrentCulture, "The Discussion with the Title {0} was not found", reply.ParentFolderId)); } // Create discussion reply and update the body field var replyItem = SPUtility.CreateNewDiscussionReply(parentFolder); replyItem["Body"] = reply.Body; // If mapped to a parent item, set the value if (reply.ParentItemId > 0) { this.logger.Info("DiscussionRepository.Reply: Mapping reply to parent item id '{0}'.", reply.ParentItemId); replyItem["ParentItemID"] = reply.ParentItemId; } replyItem.Update(); return this.binder.Get<DiscussionReply>(replyItem); }