/// <summary> /// Setups the default values. /// </summary> public override void AddSampleData() { Message message = new Message(1); message.Name = "Welcome to your new SharePoint Forum"; message.UserId = 1; message.Body = "<DIV>This is an example post in your SharePoint Forum installation. You may delete this post, this topic and even this forum if you like since everything seems to be working!</DIV>"; RepositoryRegistry.MessageRepository.Save(message); }
/// <summary> /// Creates the dto. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public static SharePointListItem CreateDto(Message message) { string[] postValues = { "Title", message.Name, "TopicID", message.TopicId.ToString(), "Body", message.Body, "UserID", message.UserId.ToString(), }; return new SharePointListItem(message.Id, postValues); }
private void btnExecute_Click(object sender, EventArgs e) { try { Random rnd = new Random(); int max1, max2, max3, max4; max1 = rnd.Next(2, 5); for (int c = 1; c < max1; c++) { string categoryName = string.Format("Test Category {0}", c+1); Category category = new Category(categoryName); int catId = RepositoryRegistry.CategoryRepository.Save(category); max2 = rnd.Next(3, 8); for (int f = 1; f < max2; f++) { string forumName = string.Format("Test Forum {0} in category {1}", f+1, categoryName); Forum forum = new Forum(catId, forumName); forum.Description = "This is just a test forum, nothing special here."; int forumId = RepositoryRegistry.ForumRepository.Save(forum); max3 = rnd.Next(3, 10); for (int t = 1; t < max3; t++) { string topicName = string.Format("Test Topic {0} in forum {1}", t+1, forumName); Topic topic = new Topic(forumId, topicName); topic.TopicStarterId = 1; int topicId = RepositoryRegistry.TopicRepository.Save(topic); max4 = rnd.Next(3, 10); for (int m = 0; m < max4; m++) { Message message = new Message(topicId); message.Name = "Just a test message."; message.Body = "You'll want to delete these messages. Use the Admin function \"Delete Forums\" to clear them out."; message.UserId = 1; RepositoryRegistry.MessageRepository.Save(message); } } } } } catch (Exception) { throw; } finally { RedirectToParent(); } }
public static Message CreateDomainObject(SharePointListItem listItem) { Message message = new Message(Convert.ToInt32(listItem["TopicID"])); message.Name = listItem["Title"]; message.UserId = Convert.ToInt32(listItem["UserID"]); message.Author = RepositoryRegistry.ForumUserRepository.GetBySharePointId(message.UserId); message.Created = Convert.ToDateTime(listItem["Created"]); message.Body = listItem["Body"]; message.Id = listItem.Id; return message; }
public void Save(Message message) { SharePointListItem listItem = MessageMapper.CreateDto(message); if (message.Id == 0) { Provider.AddListItem(ForumConstants.Lists_Posts, listItem); // TopicRepository.IncreasePostCount(message.TopicId); } else { Provider.UpdateListItem(ForumConstants.Lists_Posts, listItem); } }
private void BuildEditLinkUI(Forum forum, Message post) { bool canEdit = false; if (ForumApplication.Instance.CurrentUser.IsAdmin) { canEdit = true; } else { if (forum.HasAccess(ForumApplication.Instance.CurrentUser, Permission.Rights.Edit) && post.Author.Id == ForumApplication.Instance.CurrentUser.Id) canEdit = true; } if (canEdit) { string editLink = ForumApplication.Instance.GetLink( SharePointForumControls.UpdateMessage, "message={0}&{1}={2}", post.Id, ForumConstants.Query_PostMethod, PostMode.Edit); Controls.Add(new LiteralControl(string.Format("<a href={0}>{1}</a> | ", editLink, this.WebPartParent.LoadResource("Text.Edit")))); } }
private void BuildReplyLinkUI(Forum forum, Message post) { if (forum.HasAccess(ForumApplication.Instance.CurrentUser, Permission.Rights.Reply)) { string replyLink = ForumApplication.Instance.GetLink( SharePointForumControls.UpdateMessage, "topic={0}&{1}={2}&message={3}", post.TopicId, ForumConstants.Query_PostMethod, PostMode.Reply, post.Id); Controls.Add(new LiteralControl( String.Format("<a href=\"{0}\">{1}</a> | ", replyLink, this.WebPartParent.LoadResource("Text.Reply")))); } }
private void BuildQuoteLinkUI(Forum forum, Message post) { bool canQuote = false; if (forum.HasAccess(ForumApplication.Instance.CurrentUser, Permission.Rights.Reply)) { canQuote = true; } if (canQuote) { string quoteLink = ForumApplication.Instance.GetLink( SharePointForumControls.UpdateMessage, "message={0}&{1}={2}", post.Id, ForumConstants.Query_PostMethod, PostMode.Quote); Controls.Add(new LiteralControl(string.Format("<a href={0}>{1}</a> ", quoteLink, this.WebPartParent.LoadResource("Text.Quote")))); } }
/// <summary> /// Adds the specified post. /// </summary> /// <param name="message">The post.</param> /// <returns></returns> public int Add(Message message) { return List.Add(message); }
public void Save(Message message) { _dao.Save(message); }
/// <summary> /// Handles the Click event of the btnPost control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> /// <remarks> /// TODO move all this crap logic to the repository or somewhere... bad bad bad /// </remarks> private void btnPost_Click(object sender, EventArgs e) { Topic parentTopic; int listItemId = 0; if (MessageMode == PostMode.Edit) { parentTopic = RepositoryRegistry.TopicRepository.GetById(topicID); listItemId = messageID; } else if (MessageMode == PostMode.New) { parentTopic = new Topic(forumID, _txtSubject.Text); parentTopic.LastPost = DateTime.Now; parentTopic.TopicStarterId = ForumApplication.Instance.SpUser.ID; topicID = RepositoryRegistry.TopicRepository.Save(parentTopic); this.WebPartParent.TopicCount++; } else { parentTopic = RepositoryRegistry.TopicRepository.GetById(topicID); } string messageTitle; if(MessageMode == PostMode.New) messageTitle = _txtSubject.Text; else messageTitle = string.Format("RE: {0}", parentTopic.Name); Message message = new Message(topicID); message.Name = messageTitle; message.Id = listItemId; message.Body = _txtBody.Text; message.UserId = ForumApplication.Instance.SpUser.ID; message.Author = ForumApplication.Instance.CurrentUser; RepositoryRegistry.MessageRepository.Save(message); // Increase the post count in the main web part this.WebPartParent.PostCount++; this.WebPartParent.PersistProperties(); // Increase the number of posts for this user message.Author.NumPosts++; RepositoryRegistry.ForumUserRepository.Save(message.Author); // Redirect to the new post string url = ForumApplication.Instance.GetLink(SharePointForumControls.ViewMessages, "topic={0}", topicID); Page.Response.Redirect(url); }
public MessageCollection FindByKeywords(string keywords) { // TODO this is broken and needs to use CAML instead MessageCollection messages = new MessageCollection(); if (keywords == null) return messages; SPSearchResultCollection searchResults = ForumApplication.Instance.SpWeb.SearchListItems(keywords); foreach(SPSearchResult result in searchResults) { if(result.ListName.ToUpper() == ForumConstants.Lists_Posts.ToUpper()) { Message message = new Message(0); message.Name = result.Title; messages.Add(message); } } return messages; }