Ejemplo n.º 1
0
    protected void btnRemoveSelected_Click(object sender, EventArgs e)
    {
        // If there user selected some items
        if (gridElem.SelectedItems.Count > 0)
        {
            RaiseOnCheckPermissions(PERMISSION_MANAGE, this);
            // Create where condition
            string where = "FriendID IN (";

            foreach (string friendId in gridElem.SelectedItems)
            {
                where += ValidationHelper.GetInteger(friendId, 0) + ",";
            }
            where = where.TrimEnd(',') + ")";
            // Get all needed friendships
            DataSet friendships = FriendInfoProvider.GetFriends(where, null);
            if (!DataHelper.DataSourceIsEmpty(friendships))
            {
                // Delete all these friendships
                foreach (DataRow friendship in friendships.Tables[0].Rows)
                {
                    FriendInfoProvider.DeleteFriendInfo(new FriendInfo(friendship));
                }
            }
            gridElem.ResetSelection();
            // Reload grid
            gridElem.ReloadData();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets and bulk updates friends. Called when the "Get and bulk update friends" button is pressed.
    /// Expects the RequestFriendship method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateFriends()
    {
        // Get the user
        UserInfo friend = UserInfoProvider.GetUserInfo("MyNewFriend");

        if (friend != null)
        {
            // Prepare the parameters
            string where = "FriendRequestedUserID = " + friend.UserID;

            // Get the data
            DataSet friends = FriendInfoProvider.GetFriends(where, null);
            if (!DataHelper.DataSourceIsEmpty(friends))
            {
                // Loop through the individual items
                foreach (DataRow friendDr in friends.Tables[0].Rows)
                {
                    // Create object from DataRow
                    FriendInfo modifyFriend = new FriendInfo(friendDr);

                    // Update the properties
                    modifyFriend.FriendStatus       = FriendshipStatusEnum.Approved;
                    modifyFriend.FriendRejectedBy   = 0;
                    modifyFriend.FriendApprovedBy   = MembershipContext.AuthenticatedUser.UserID;
                    modifyFriend.FriendApprovedWhen = DateTime.Now;

                    // Save the changes
                    FriendInfoProvider.SetFriendInfo(modifyFriend);
                }

                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 3
0
    protected void btnRemoveSelected_Click(object sender, EventArgs e)
    {
        // If there user selected some items
        if (gridElem.SelectedItems.Count > 0)
        {
            RaiseOnCheckPermissions(PERMISSION_MANAGE, this);

            // Get all needed friendships
            DataSet friendships = FriendInfoProvider.GetFriends()
                                  .WhereIn("FriendID", gridElem.SelectedItems.Select(id => ValidationHelper.GetInteger(id, 0)).ToList());

            if (!DataHelper.DataSourceIsEmpty(friendships))
            {
                // Delete all these friendships
                foreach (DataRow friendship in friendships.Tables[0].Rows)
                {
                    FriendInfo fi = new FriendInfo(friendship);
                    if (fi.FriendStatus != FriendshipStatusEnum.Rejected)
                    {
                        FriendInfoProvider.DeleteFriendInfo(fi);
                    }
                }
            }
            gridElem.ResetSelection();
            // Reload grid
            gridElem.ReloadData();
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Deletes all friends of "My new user". Called when the "Delete friends" button is pressed.
    /// Expects the CreateFriend method to be run first.
    /// </summary>
    private bool DeleteFriends()
    {
        // Get the user
        UserInfo friend = UserInfoProvider.GetUserInfo("MyNewFriend");

        if (friend != null)
        {
            // Prepare the parameters
            string where = "FriendRequestedUserID = " + friend.UserID;

            // Get all user's friendships
            DataSet friends = FriendInfoProvider.GetFriends(where, null);
            if (!DataHelper.DataSourceIsEmpty(friends))
            {
                // Delete all the friendships
                foreach (DataRow friendDr in friends.Tables[0].Rows)
                {
                    FriendInfo deleteFriend = new FriendInfo(friendDr);

                    FriendInfoProvider.DeleteFriendInfo(deleteFriend);
                }
            }
            else
            {
                // Change the info message
                apiDeleteFriends.InfoMessage = "The user 'My new friend' doesn't have any friends. The user has been deleted.";
            }

            // Finally delete the user "My new friend"
            UserInfoProvider.DeleteUser(friend);

            return(true);
        }

        return(false);
    }