private async Task <string> GetCommunityIdAsync(Page communityPage, CommunityTypes type) { string result = null; string linkString = (type == CommunityTypes.Public) ? "#public_followers.module.clear.people_module._module" : "#group_followers.module.clear.people_module._module"; ElementHandle communityFollowersElement = await communityPage.QuerySelectorAsync(linkString); if (communityFollowersElement != null) { ElementHandle communityFollowersSearchElement = await communityFollowersElement.QuerySelectorAsync("a.module_header"); string communityFollowersSearchLink = await communityFollowersSearchElement.EvaluateFunctionAsync <string>("('a', a => a.href)"); string linkLastPart = communityFollowersSearchLink.Split("=").Last(); if (!string.IsNullOrEmpty(linkLastPart)) { result = linkLastPart; } } else { bool isPersonalPage = await IsPersonalPage(communityPage); if (isPersonalPage) { //создать пользователя } } return(result); }
/// <summary> /// Creates a new community. /// </summary> /// <param name="title">Community title.</param> /// <param name="description">Community description (ignored if type is <see cref="CommunityTypes.Public"/>).</param> /// <param name="type">Community type.</param> /// <param name="subtype">Public page subtype.</param> /// <returns>Returns an id of a created community.</returns> public async Task <Response <int> > Create(string title, string description = null, CommunityTypes type = CommunityTypes.Public, CommunitySubtypes?subtype = null) => await Request <int>("create", new MethodParams { { "title", title, true }, { "description", description }, { "type", Utils.ToEnumString(type) }, { "subtype", subtype.HasValue ? subtype : 0 } });
/// <summary> /// Gets the communities and folders which can be used as parent while creating a new /// community/folder/content by the specified user. /// </summary> /// <param name="userId">User for which the parent communities/folders are being fetched</param> /// <param name="currentCommunityId">Id of the current community which should not be returned</param> /// <param name="excludeCommunityType">Community type which needs to be excluded</param> /// <param name="userRoleOnParentCommunity">Specified user should have given user role or higher on the given community</param> /// <param name="currentUserRole">Current user role</param> /// <returns>List of communities folders</returns> public IEnumerable <Community> GetParentCommunities( long userId, long currentCommunityId, CommunityTypes excludeCommunityType, UserRole userRoleOnParentCommunity, UserRole currentUserRole) { Expression <Func <Community, bool> > condition = null; // TODO: How do we ensure that we consistently pass conditions like IsDeleted = false to all queries? if (currentUserRole == UserRole.SiteAdmin) { // For site administrator, need to get all the communities/folders. if (excludeCommunityType == CommunityTypes.None) { // If parent communities are retrieved for Contents (when excludeCommunityType is None), need to send the "None" Community of site admin. condition = (Community c) => (c.CommunityTypeID != (int)CommunityTypes.User || c.CreatedByID == userId) && !(bool)c.IsDeleted && c.CommunityID != currentCommunityId; } else { if (currentCommunityId > 0) { var childCommunities = GetAllChildrenCommunities(currentCommunityId); // If parent communities are retrieved for Communities (when excludeCommunityType is User), no need to send the "None" Community. condition = (Community c) => !(bool)c.IsDeleted && c.CommunityTypeID != (int)excludeCommunityType && c.CommunityID != currentCommunityId && !childCommunities.Contains(c.CommunityID); } else { // If parent communities are retrieved for Communities (when excludeCommunityType is User), no need to send the "None" Community. condition = (Community c) => !(bool)c.IsDeleted && c.CommunityTypeID != (int)excludeCommunityType && c.CommunityID != currentCommunityId; } } } else { if (currentCommunityId > 0) { var childCommunities = GetAllChildrenCommunities(currentCommunityId); // User who is creating the community should be equal or higher role than the userRoleOnParentCommunity. // 1. While creating communities/folder, User Community Type (Visitor folder) to be excluded. // 2. While creating contents, User Community Type (Visitor folder) to be included. condition = (Community c) => !(bool)c.IsDeleted && c.CommunityTypeID != (int)excludeCommunityType && c.CommunityID != currentCommunityId && c.UserCommunities.Where(u => u.UserID == userId && u.RoleID >= (int)userRoleOnParentCommunity).FirstOrDefault() != null && !childCommunities.Contains(c.CommunityID); } else { // User who is creating the community should be equal or higher role than the userRoleOnParentCommunity. // 1. While creating communities/folder, User Community Type (Visitor folder) to be excluded. // 2. While creating contents, User Community Type (Visitor folder) to be included. condition = (Community c) => !(bool)c.IsDeleted && c.CommunityTypeID != (int)excludeCommunityType && c.CommunityID != currentCommunityId && c.UserCommunities.Where(u => u.UserID == userId && u.RoleID >= (int)userRoleOnParentCommunity).FirstOrDefault() != null; } } Func <Community, object> orderBy = (Community c) => c.CommunityID; return(EarthOnlineDbContext.Community.Where(condition).OrderBy(orderBy)); }