コード例 #1
0
ファイル: ForumMapper.cs プロジェクト: bsimser/spforums
		/// <summary>
		/// Creates the specified forum.
		/// </summary>
		/// <param name="forum">The forum.</param>
		/// <returns></returns>
		public static SharePointListItem CreateDto(Forum forum)
		{
			string[] values = {
				"Title", forum.Name,
				"Description", forum.Description,
				"CategoryID", forum.CategoryId.ToString(),
			};

			return new SharePointListItem(forum.Id, values);
		}
コード例 #2
0
ファイル: EditForum.cs プロジェクト: bsimser/spforums
		private void LoadControlValues()
		{
			id = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
			if (id == 0)
				forum = new Forum(1, "New Forum");
			else
				forum = RepositoryRegistry.ForumRepository.GetById(id);

			txtName.Text = forum.Name;
			ddlCategories.SelectedIndex = forum.CategoryId - 1;
			txtDescription.Text = forum.Description;
		}
コード例 #3
0
ファイル: CreateSampleData.cs プロジェクト: bsimser/spforums
		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();
			}
		}
コード例 #4
0
ファイル: ForumMapper.cs プロジェクト: bsimser/spforums
		/// <summary>
		/// Loads the specified list item.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <returns></returns>
		public static Forum CreateDomainObject(SharePointListItem listItem)
		{
			int categoryId = Convert.ToInt32(listItem["CategoryID"]);
			Forum forum = new Forum(listItem.Id, categoryId, listItem["Title"]);

			forum.Description = listItem["Description"];

			// TODO I think this is wrong. The last post should be set when
			// a topic is added, not modified
			forum.LastPost = Convert.ToDateTime(listItem["Modified"]);

			return forum;
		}
コード例 #5
0
ファイル: ForumDao.cs プロジェクト: bsimser/spforums
		public int Save(Forum forum)
		{
			SharePointListItem listItem = ForumMapper.CreateDto(forum);
			int newId = 0;

			if (forum.Id == 0)
			{
				newId = Provider.AddListItem(ForumConstants.Lists_Forums, listItem);
				SetupDefaultPermissions(newId);
			}
			else
			{
				newId = Provider.UpdateListItem(ForumConstants.Lists_Forums, listItem);
			}

			return newId;
		}
コード例 #6
0
		private void DisplayGroups(Group group, Forum forum)
		{
			Controls.Add(new LiteralControl("<tr class=\"ms-alternating\">"));

			Controls.Add(new LiteralControl("<td>&nbsp;</td>"));

			Controls.Add(new LiteralControl(string.Format("<td>{0}</td>", group.Name)));

			string editLink = ForumApplication.Instance.GetLink(SharePointForumControls.ManageForumGroupPermissions, "forum={0}&group={1}", forum.Id, group.Id);
			Controls.Add(new LiteralControl(string.Format("<td align=center><a href=\"{0}\">Edit</a></td>", editLink)));

			string permissionDisplay = "None";
			foreach (DictionaryEntry permission in forum.Permissions)
			{
				if (Convert.ToInt32(permission.Key) == group.Id)
				{
					Permission perm = new Permission(permission.Value.ToString());
					permissionDisplay = perm.DisplayString;
				}
			}
			Controls.Add(new LiteralControl(string.Format("<td align=center>{0}</td>", permissionDisplay)));

			Controls.Add(new LiteralControl("</tr>"));
		}
コード例 #7
0
ファイル: BaseForumControl.cs プロジェクト: bsimser/spforums
		protected void DisplayMessages(MessageCollection messages, Forum forum)
		{
			foreach (Message post in messages)
			{
				Controls.Add(new LiteralControl("<tr>"));

				Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" width=140px>"));
				Controls.Add(new LiteralControl(string.Format("{0}", HtmlUtility.CreateProfileLink(post.Author))));
				Controls.Add(new LiteralControl("</td>"));

				Controls.Add(new LiteralControl("<td class=\"ms-TPHeader\" width=80%>"));
				Controls.Add(new LiteralControl("<table cellspacing=0 cellpadding=0 width=100%>"));
				Controls.Add(new LiteralControl("<tr>"));
				Controls.Add(new LiteralControl(string.Format("<td><strong>{0}:&nbsp;</strong>{1}</td>", this.WebPartParent.LoadResource("Text.Posted"), post.Created)));
				Controls.Add(new LiteralControl(string.Format("<td align=right>")));

				if(forum != null)
				{
					BuildReplyLinkUI(forum, post);
					BuildEditLinkUI(forum, post);
					BuildQuoteLinkUI(forum, post);
				}

				Controls.Add(new LiteralControl(string.Format("</td>")));
				Controls.Add(new LiteralControl("</tr>"));
				Controls.Add(new LiteralControl("</table>"));
				Controls.Add(new LiteralControl("</td>"));

				Controls.Add(new LiteralControl("</tr>"));

				Controls.Add(new LiteralControl("<tr class=\"ms-alternating\">"));
				Controls.Add(new LiteralControl(string.Format("<td valign=\"top\">{0}</td>", FillUserInfoBox(post.Author))));
				Controls.Add(new LiteralControl(string.Format("<td valign=\"top\">{0}</td>", post.Body)));
				Controls.Add(new LiteralControl("</tr>"));

				Controls.Add(new LiteralControl("<tr>"));
				Controls.Add(new LiteralControl("<td colspan=2 class=\"ms-ToolPaneTitle\" style=\"height:5px\"></td>"));
				Controls.Add(new LiteralControl("</tr>"));
			}
		}
コード例 #8
0
ファイル: BaseForumControl.cs プロジェクト: bsimser/spforums
		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>&nbsp;|&nbsp;", editLink,
					this.WebPartParent.LoadResource("Text.Edit"))));
			}
		}
コード例 #9
0
ファイル: BaseForumControl.cs プロジェクト: bsimser/spforums
		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>&nbsp;|&nbsp;", replyLink, 
						this.WebPartParent.LoadResource("Text.Reply"))));
			}
		}
コード例 #10
0
ファイル: BaseForumControl.cs プロジェクト: bsimser/spforums
		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>&nbsp;", 
					quoteLink, this.WebPartParent.LoadResource("Text.Quote"))));
			}
		}
コード例 #11
0
ファイル: ForumCollection.cs プロジェクト: bsimser/spforums
		/// <summary>
		/// Adds the specified forum.
		/// </summary>
		/// <param name="forum">The forum.</param>
		/// <returns></returns>
		public int Add(Forum forum)
		{
			return List.Add(forum);
		}
コード例 #12
0
ファイル: ForumRepository.cs プロジェクト: bsimser/spforums
		public int Save(Forum forum)
		{
			return _dao.Save(forum);
		}
コード例 #13
0
ファイル: EditForum.cs プロジェクト: bsimser/spforums
		private int SaveControlValues()
		{
			id = ValidInt(HttpContext.Current.Request.QueryString["forum"]);
			if (id == 0)
				forum = new Forum(1, "");
			else
				forum = RepositoryRegistry.ForumRepository.GetById(id);

			forum.Name = txtName.Text;
			forum.CategoryId = ddlCategories.SelectedIndex + 1;
			forum.Description = txtDescription.Text;

			return RepositoryRegistry.ForumRepository.Save(forum);
		}
コード例 #14
0
ファイル: ForumListBuilder.cs プロジェクト: bsimser/spforums
		public override void AddSampleData()
		{
			Forum forum = new Forum(1, "Test Forum 1");
			forum.Description = "This is just a test forum, nothing special here.";
			RepositoryRegistry.ForumRepository.Save(forum);
		}