Ejemplo n.º 1
0
        public void InsertToGroup(User user, List<String> listVkIdFriends)
        {
            int i = 1;
            UserMapper userMapper = new UserMapper();
            ListFriendsMapper listFriendsMapper = new ListFriendsMapper();
            List<ListFriends> listFriends = new List<ListFriends>();
            FriendsMapper friendsMapper = new FriendsMapper();
            foreach (var vkIdFriend in listVkIdFriends)
            {
                ListFriends listFriend = new ListFriends(user.GetId(), friendsMapper.FindByVkId(vkIdFriend).GetId());
                listFriends.Add(listFriend);
            }
            foreach (var friend in listFriends)
            {
                GroupMapper groupMapper = new GroupMapper();
                Friend friendObj = friendsMapper.FindById(friend.GetIdFriend());
                String VkId = friendObj.GetVkId();

                List<String> listgroup = vkClient.GroupsList(VkId);
                List<Group> groupsFriend = new List<Group>(); ;
                List<GroupsFriends> GroupsFriendses = new List<GroupsFriends>();
                int idFriend = friendsMapper.FindByVkId(friendObj.GetVkId()).GetId();
                GroupsFriendsMapper groupsFriendsMapper = new GroupsFriendsMapper();
                Group group = null;
                foreach (var vkidGroup in listgroup)
                {
                    group = new Group(vkidGroup);
                    groupsFriend.Add(group);
                }
                groupMapper.Insert(groupsFriend);

                foreach (var vkidGroup in listgroup)
                {
                    GroupsFriends groupsFriends = new GroupsFriends(idFriend, groupMapper.FindByVkId(vkidGroup).GetId());
                    GroupsFriendses.Add(groupsFriends);
                }
                groupsFriendsMapper.Insert(GroupsFriendses);
                Console.WriteLine("--------------------Friend number {0}", i);
                i++;
                listgroup.Clear();
            }
        }
Ejemplo n.º 2
0
 private Group FindBy(String SQL)
 {
     dbMaster.OpenConnection();
     Group group = null;
     try
     {
         MySqlCommand command = dbMaster.GetConnection().CreateCommand();
         command.CommandText = SQL;
         command.ExecuteNonQuery();
         using (MySqlDataReader reader = command.ExecuteReader())
         {
             while (reader.Read())
             {
                 group = new Group(Convert.ToInt32(reader["id"]), reader["id_vk"].ToString());
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     dbMaster.CloseConnection();
     return group;
 }