public void AddUser(VkBrwUser user) { Users.Add(user); if (user.Communitites.Count > 0) { foreach (VkBrwCommunity community in user.Communitites) { VkBrwCommunity existingCommunity = Communities.FirstOrDefault(c => c.CommunityId == community.CommunityId); if (existingCommunity == null) { Communities.Add(community); } else { VkBrwUser existingUser = existingCommunity.Users.FirstOrDefault(u => u.ProfileLink == user.ProfileLink); if (existingUser == null) { existingCommunity.Users.Add(user); } } } } }
public async Task <VkApiCommunity> DiscoverCommunityAsync(string groupId) { VkApiCommunity result = null; try { //"kate_kul" error 100 var groupInfo = await UserApi.Groups.GetByIdAsync(null, groupId, GroupsFields.All); if (groupInfo.Count == 1) { VkApiCommunity community = new VkApiCommunity(this, groupInfo[0]); if (Communities.FirstOrDefault(c => c.Id == community.Id) == null) { Communities.Add(community); } result = community; } } catch (ParameterMissingOrInvalidException) { Console.WriteLine("Error discovering community " + groupId + ": community not found."); } catch (Exception e) { Console.WriteLine("Error discovering community " + groupId + ": " + e); } return(result); }
/// <summary> /// Get community by id /// </summary> public Community <T> GetCommunityById(int communityId) { return(Communities.FirstOrDefault(i => i.Id == communityId)); }