示例#1
0
        /// <summary>
        /// Note: You cannot add end users to groups they go in organizations.        
        /// </summary>
        /// <param name="group"></param>
        /// <returns></returns>
        public int CreateOrUpdateGroup(Group group)
        {
            //Check to see if a group already exists
            var oldGroups = GetGroups().Where(x => x.Name == group.Name);
            if (oldGroups.Count() > 0)
            {
                group.Id = oldGroups.First().Id;
                if (UpdateGroup(group))
                    return group.Id;

                return -1;
            }

            //Make sure to use the UserIds not the Users
            group.CopyUsersToUserIds();

            var request = new ZenRestRequest
            {
                Method = Method.POST,
                Resource = Groups + ".xml"
            };

            request.AddBody(group);

            var res = Execute(request);

            return GetIdFromLocationHeader(res);
        }
示例#2
0
        public bool UpdateGroup(Group group)
        {
            //Make sure to use the UserIds not the Users
            group.CopyUsersToUserIds();

            var request = new ZenRestRequest
            {
                Method = Method.PUT,
                Resource = string.Format("{0}/{1}.xml", Groups, group.Id)
            };

            request.AddBody(group);

            var res = Execute(request);

            return res.StatusCode == System.Net.HttpStatusCode.OK;
        }