Пример #1
0
		public void Delete(Topic topic)
		{
			foreach (Message message in topic.Messages)
			{
				Provider.DeleteListItem(ForumConstants.Lists_Posts, message.Id);
			}
			Provider.DeleteListItem(ForumConstants.Lists_Topics, topic.Id);
		}
Пример #2
0
		public static SharePointListItem CreateDto(Topic topic)
		{
			string[] topicValues = {
				"Title", topic.Name,
				"ForumID", topic.ForumId.ToString(),
				"Views", topic.Views.ToString(),
				"TopicStarterID", topic.TopicStarterId.ToString(),
			};

			return new SharePointListItem(topic.Id, topicValues);
		}
Пример #3
0
		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
		public static Topic CreateDomainObject(SharePointListItem item)
		{
			Topic topic = new Topic(item.Id, Convert.ToInt32(item["ForumID"]), item["Title"]);

			topic.Views = Convert.ToInt32(item["Views"]);
			topic.TopicStarterId = Convert.ToInt32(item["TopicStarterID"]);
			topic.Author = RepositoryRegistry.ForumUserRepository.GetBySharePointId(topic.TopicStarterId);

			// Built in values from SharePoint list
			// TODO might be the wrong value
			topic.LastPost = Convert.ToDateTime(item["Modified"]);

			return topic;
		}
Пример #5
0
		private void InitControlVariables()
		{
			if(this.Page.IsPostBack)
			{
				topicID = (int) ViewState["topicID"];
			}
			else
			{
				ViewState["topicID"] = topicID;				
			}

			this.topic = RepositoryRegistry.TopicRepository.GetById(topicID);
			base.ParentLink = ForumApplication.Instance.GetLink(SharePointForumControls.ViewTopics, "forum={0}", forumID);
		}
Пример #6
0
		public int Save(Topic topic)
		{
			SharePointListItem listItem = TopicMapper.CreateDto(topic);
			int newTopicId = 0;

			if (topic.Id == 0)
			{
				newTopicId = Provider.AddListItem(ForumConstants.Lists_Topics, listItem);
				RepositoryRegistry.ForumRepository.IncreaseCount(topic.ForumId);
			}
			else
			{
				newTopicId = Provider.UpdateListItem(ForumConstants.Lists_Topics, listItem);
			}

			return newTopicId;
		}
Пример #7
0
		/// <summary>
		/// Creates the domain object.
		/// </summary>
		/// <param name="item">The item.</param>
		/// <returns></returns>
		public static Topic CreateDomainObject(SharePointListItem item)
		{
			Topic topic = new Topic(item.Id, Convert.ToInt32(item["ForumID"]), item["Title"]);

			topic.Views = Convert.ToInt32(item["Views"]);
			topic.TopicStarterId = Convert.ToInt32(item["TopicStarterID"]);
			topic.Author = RepositoryRegistry.ForumUserRepository.GetBySharePointId(topic.TopicStarterId);
			
			if(item["NumPosts"] == null || item["NumPosts"] == string.Empty)
				topic.NumPosts = 0;
			else
				topic.NumPosts = Convert.ToInt32(item["NumPosts"]);

			MessageCollection messages = topic.Messages;
			messages.Sort("Modified", SortDirection.Descending);
			topic.LastPost = Convert.ToDateTime(messages[messages.Count-1].Modified);

			return topic;
		}
Пример #8
0
		public void Delete(Topic topic)
		{
			_dao.Delete(topic);
		}
Пример #9
0
		public int Save(Topic topic)
		{
			return _dao.Save(topic);
		}
Пример #10
0
		/// <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);
		}
Пример #11
0
		/// <summary>
		/// Adds the specified topic.
		/// </summary>
		/// <param name="topic">The topic.</param>
		/// <returns></returns>
		public int Add(Topic topic)
		{
			return List.Add(topic);
		}
Пример #12
0
		/// <summary>
		/// Setups the default values.
		/// </summary>
		public override void AddSampleData()
		{
			Topic topic = new Topic(1, "Welcome to your new SharePoint Forum");
			topic.TopicStarterId = 1;
			RepositoryRegistry.TopicRepository.Save(topic);
		}