Exemplo n.º 1
0
        async Task <bool> IGroup.RemoveAccountAsync(IAccount account, CancellationToken cancellationToken)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            IGroupMembership foundMembership = null;

            await this.AsInterface.GetAccountMemberships().ForEachAsync(
                item =>
            {
                if ((item as IInternalGroupMembership).AccountHref.Equals(account.Href, StringComparison.InvariantCultureIgnoreCase))
                {
                    foundMembership = item;
                }

                return(foundMembership != null);
            }, cancellationToken).ConfigureAwait(false);

            if (foundMembership == null)
            {
                throw new InvalidOperationException("The specified account does not belong to this group.");
            }

            return(await foundMembership.DeleteAsync(cancellationToken).ConfigureAwait(false));
        }
Exemplo n.º 2
0
        async Task <bool> IGroup.RemoveAccountAsync(string hrefOrEmailOrUsername, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(hrefOrEmailOrUsername))
            {
                throw new ArgumentNullException(nameof(hrefOrEmailOrUsername));
            }

            IGroupMembership foundMembership = null;
            var iterator = this.AsInterface.GetAccountMemberships();

            while (await iterator.MoveNextAsync(cancellationToken).ConfigureAwait(false))
            {
                foreach (var item in iterator.CurrentPage)
                {
                    IAccount account = await item.GetAccountAsync(cancellationToken).ConfigureAwait(false);

                    if (account.Href.Equals(hrefOrEmailOrUsername, StringComparison.InvariantCultureIgnoreCase) ||
                        account.Email.Equals(hrefOrEmailOrUsername, StringComparison.InvariantCultureIgnoreCase) ||
                        account.Username.Equals(hrefOrEmailOrUsername, StringComparison.InvariantCultureIgnoreCase))
                    {
                        foundMembership = item;
                    }

                    if (foundMembership != null)
                    {
                        break;
                    }
                }

                if (foundMembership != null)
                {
                    break;
                }
            }

            if (foundMembership == null)
            {
                throw new InvalidOperationException("The specified account does not belong to this group.");
            }

            return(await foundMembership.DeleteAsync(cancellationToken).ConfigureAwait(false));
        }