Exemple #1
0
		/// <summary>
		/// Creates a link to the profile page for a given user. Used
		/// in various places for other users to navigate to a persons
		/// profile page.
		/// </summary>
		/// <param name="user">The user to link to.</param>
		/// <returns>A formatted link that can be used in any HTML display</returns>
		public static string CreateProfileLink(ForumUser user)
		{
			string link;

			string profileLink = ForumApplication.Instance.GetLink(SharePointForumControls.ViewProfile, "userid={0}", user.UserId);
			link = String.Format("<a href=\"{0}\">{1}</a>", profileLink, user.Name);

			return link;
		}
Exemple #2
0
		/// <summary>
		/// Determines whether the specified user has access 
		/// to any forum in the category.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <param name="right">The right.</param>
		/// <returns>
		/// 	<c>true</c> if the specified user has access; otherwise, <c>false</c>.
		/// </returns>
		public bool HasAccess(ForumUser user, Permission.Rights right)
		{
			foreach (Forum forum in Forums)
			{
				if (forum.HasAccess(user, right))
				{
					return true;
				}
			}

			return false;
		}
Exemple #3
0
		/// <summary>
		/// Loads the groups for user.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <param name="user">The user.</param>
		private static void LoadGroupsForUser(SharePointListItem listItem, ForumUser user)
		{
			string groupIds = listItem["Groups"];
			string delim = ";";
			char[] delimArray = delim.ToCharArray();
			string[] groupArray = groupIds.Split(delimArray);
			foreach (string s in groupArray)
			{
				int groupId = Convert.ToInt32(s);
				Group group = RepositoryRegistry.GroupRepository.FindById(groupId);
				user.Groups.Add(group);
			}
		}
Exemple #4
0
		/// <summary>
		/// Loads the share point info for user.
		/// </summary>
		/// <param name="user">The user.</param>
		private static void LoadSharePointInfoForUser(ForumUser user)
		{
			try
			{
				SPUser spCurrentUser = ForumApplication.Instance.SpWeb.SiteUsers.GetByID(user.UserId);
				if(null != spCurrentUser)
				{
					user.Name = spCurrentUser.Name;
					user.Email = spCurrentUser.Email;
				}
			}
			catch (Exception)
			{
			}
		}
Exemple #5
0
		/// <summary>
		/// Creates the dto.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public static SharePointListItem CreateDto(ForumUser user)
		{
			string[] values = {
				"Title", user.Name,
				"UserID", user.UserId.ToString(),
				"LastVisit", user.LastVisit.ToString(),
				"NumPosts", user.NumPosts.ToString(),
				"IsAdmin", user.IsAdmin.ToString(),
				"Groups", user.Id == 0
					? ForumApplication.Instance.GetDefaultGroupsForNewUser()
					: user.Groups.ToString(),
			};

			return new SharePointListItem(user.Id, values);
		}
Exemple #6
0
		/// <summary>
		/// Creates the domain object.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <returns></returns>
		public static ForumUser CreateDomainObject(SharePointListItem listItem)
		{
			ForumUser user = new ForumUser();

			user.Id = Convert.ToInt32(listItem.Id);
			user.LastVisit = Convert.ToDateTime(listItem["LastVisit"]);
			user.UserId = Convert.ToInt32(listItem["UserID"]);
			user.NumPosts = Convert.ToInt32(listItem["NumPosts"]);
			user.Joined = Convert.ToDateTime(listItem["Created"]);
			user.IsAdmin = Convert.ToBoolean(listItem["IsAdmin"]);

			LoadGroupsForUser(listItem, user);
			LoadSharePointInfoForUser(user);

			return user;
		}
Exemple #7
0
		private void SaveControlValues()
		{
			userId = ValidInt(HttpContext.Current.Request.QueryString["id"]);
			user = RepositoryRegistry.ForumUserRepository.GetById(userId);

			user.IsAdmin = cbIsAdmin.Checked;

			foreach (object control in Controls)
			{
				if (control is TableRow)
				{
					TableRow row = control as TableRow;
					foreach (object o in row.Controls)
					{
						if (o is TableCell)
						{
							TableCell cell = o as TableCell;
							foreach (object control1 in cell.Controls)
							{
								if (control1 is CheckBox)
								{
									CheckBox cb = control1 as CheckBox;
									int id = Convert.ToInt32(cb.ID);
									if (id != 0)
									{
										Group group = RepositoryRegistry.GroupRepository.FindById(id);
										Group userGroup = user.Groups.Find(group.Id);
										if (cb.Checked)
										{
											if (userGroup == null)
												user.Groups.Add(group);
										}
										else
										{
											if (userGroup != null)
												user.Groups.Remove(userGroup);
										}
									}
								}
							}
						}
					}
				}
			}

			RepositoryRegistry.ForumUserRepository.Save(user);
		}
Exemple #8
0
		public int Save(ForumUser user)
		{
			int userId;

			SharePointListItem listItem = UserMapper.CreateDto(user);

			if (user.Id == 0)
			{
				userId = Provider.AddListItem(ForumConstants.Lists_Users, listItem);
			}
			else
			{
				userId = Provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
			}

			return userId;
		}
Exemple #9
0
		public int Save(ForumUser user)
		{
			int userId;

			SharePointListProvider provider = new SharePointListProvider(ForumApplication.Instance.SpWeb);
			SharePointListItem listItem = UserMapper.CreateDto(user);

			if (user.Id == 0)
			{
				userId = provider.AddListItem(ForumConstants.Lists_Users, listItem);
			}
			else
			{
				userId = provider.UpdateListItem(ForumConstants.Lists_Users, listItem);
			}

			return userId;
		}
Exemple #10
0
		private string FillUserInfoBox(ForumUser user)
		{
			StringBuilder sb = new StringBuilder();

			sb.AppendFormat("{0}: {1}<br>", this.WebPartParent.LoadResource("UserInfoBox.Joined"), user.Joined.ToShortDateString());
			sb.AppendFormat("{0}: {1}<br>", this.WebPartParent.LoadResource("UserInfoBox.Posts"), user.NumPosts);

			return sb.ToString();
		}
Exemple #11
0
		public void UserShouldHaveAccess()
		{
			ForumUser user = new ForumUser();
			Category category = new Category("Test");
			Assert.AreEqual(true, category.HasAccess(user, Permission.Rights.Add));
		}
		/// <summary>
		/// Indexes the of.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public int IndexOf(ForumUser user)
		{
			return List.IndexOf(user);
		}
		/// <summary>
		/// Determines whether [contains] [the specified user].
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns>
		/// 	<c>true</c> if [contains] [the specified user]; otherwise, <c>false</c>.
		/// </returns>
		public bool Contains(ForumUser user)
		{
			return List.Contains(user);
		}
Exemple #14
0
		/// <summary>
		/// Determines whether the specified user has access.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <param name="rights">The rights.</param>
		/// <returns>
		/// 	<c>true</c> if the specified user has access; otherwise, <c>false</c>.
		/// </returns>
		public bool HasAccess(ForumUser user, Permission.Rights rights)
		{
			foreach (Group userGroup in user.Groups)
			{
				Permission perm = Permissions[userGroup.Id] as Permission;
				if (perm != null)
				{
					if (perm.HasPermission(rights))
						return true;
				}
			}

			return false;
		}
Exemple #15
0
		private void LoadControlValues()
		{
			userId = ValidInt(HttpContext.Current.Request.QueryString["id"]);
			user = RepositoryRegistry.ForumUserRepository.GetById(userId);
			cbIsAdmin.Checked = user.IsAdmin;
		}
		public int Save(ForumUser user)
		{
			return _dao.Save(user);
		}
Exemple #17
0
		private void CreateUser(int id)
		{
			ForumUser user = new ForumUser();
			user.Name = ForumApplication.Instance.SpUser.Name;
			user.Id = id;
			user.UserId = ForumApplication.Instance.SpUser.ID;
			user.LastVisit = DateTime.Now;
			user.NumPosts = id == 1 ? 1 : 0;
			user.IsAdmin = id == 1 ? true : false;
			Save(user);
		}
		/// <summary>
		/// Adds the specified user.
		/// </summary>
		/// <param name="user">The user.</param>
		/// <returns></returns>
		public int Add(ForumUser user)
		{
			return List.Add(user);
		}