/// <summary>
        /// Updates the specified group membership with the specified request.
        /// </summary>
        /// <param name="membershipId">It of the group membership to update.</param>
        /// <param name="memRequest">BoxGroupMembershipRequest object.</param>
        /// <param name="fields">Attribute(s) to include in the response.</param>
        /// <returns>The updated group membership.</returns>
        public async Task <BoxGroupMembership> UpdateGroupMembershipAsync(string membershipId, BoxGroupMembershipRequest memRequest, IEnumerable <string> fields = null)
        {
            membershipId.ThrowIfNullOrWhiteSpace("membershipId");
            memRequest.ThrowIfNull("memRequest").Role.ThrowIfNullOrWhiteSpace("role");

            BoxRequest request = new BoxRequest(_config.GroupMembershipEndpointUri, membershipId)
                                 .Param(ParamFields, fields)
                                 .Method(RequestMethod.Put)
                                 .Payload(_converter.Serialize <BoxGroupMembershipRequest>(memRequest));

            IBoxResponse <BoxGroupMembership> response = await ToResponseAsync <BoxGroupMembership>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }
Example #2
0
        /// <summary>
        /// Add a user to a group
        /// </summary>
        /// <param name="membershipRequest">The request object that contains the user Id and group Id</param>
        /// <param name="fields">Optional fields to return</param>
        /// <returns>The group membership created</returns>
        public async Task <BoxGroupMembership> AddMemberToGroupAsync(BoxGroupMembershipRequest membershipRequest, List <string> fields = null)
        {
            membershipRequest.ThrowIfNull("membershipRequest")
            .Group.Id.ThrowIfNullOrWhiteSpace("Group.Id");
            membershipRequest.User.Id.ThrowIfNullOrWhiteSpace("User.Id");

            BoxRequest request = new BoxRequest(_config.GroupMembershipEndpointUri)
                                 .Method(RequestMethod.Post)
                                 .Param(ParamFields, fields)
                                 .Payload(_converter.Serialize <BoxGroupMembershipRequest>(membershipRequest));

            IBoxResponse <BoxGroupMembership> response = await ToResponseAsync <BoxGroupMembership>(request).ConfigureAwait(false);

            return(response.ResponseObject);
        }