/// <summary>
        /// Creates the organization in TrueVault.
        /// </summary>
        /// <param name="vaultName">Name of the vault in true vault. Typically will be the Org name. However, if you want to create something different, this is the field to use</param>
        /// <param name="userName">Name of the truevault user.</param>
        /// <param name="groupName">Name of the group in truevault.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">
        /// Cannot create vault in TrueVault
        /// or
        /// Cannot create group in TrueVault
        /// </exception>
        public CreateOrgResult CreateOrganization(string vaultName, string userName, string groupName = "")
        {
            if (vaultName.Length > 75)
            {
                vaultName = vaultName.Substring(0, 75);
            }

            if (groupName.Length > 75)
            {
                groupName = groupName.Substring(0, 75);
            }

            //var password = EncryptionHelper.GetRandomString(20);

            //var userResult = this.CreateUser(userName, password);

            //if (userResult == null || userResult.Result != Success)
            //{
            //    throw new Exception("Cannot create user in TrueVault");
            //}

            var vaultResult = this.CreateVault(vaultName);

            if (vaultResult == null || vaultResult.Result != Success)
            {
                throw new Exception("Cannot create vault in TrueVault");
            }

            GroupFullResult groupResult = null;

            groupResult = !string.IsNullOrEmpty(groupName)
                ? this.GetGroupByName(groupName)
                : this.CreateGroup(vaultResult.Vault.Id, vaultName, string.Empty);

            if (groupResult == null && !string.IsNullOrEmpty(groupName))
            {
                groupResult = this.CreateGroup(vaultResult.Vault.Id, groupName, string.Empty);
            }

            if (groupResult == null || groupResult.Result != Success)
            {
                throw new Exception("Cannot create group in TrueVault");
            }

            return(new CreateOrgResult
            {
                GroupId = groupResult.Group.Group_id,
                VaultId = vaultResult.Vault.Id
            });
        }
        public void AddUserToGroups(List <UserOrganizationItem> organizations, string userId, AllGroupResult groups, string groupId = "", string groupName = "")
        {
            foreach (var org in organizations)
            {
                var orgName = org.Organization.OrganizationName;

                if (orgName.Length > 75)
                {
                    orgName = orgName.Substring(0, 75);
                }

                var group = groups.Groups.SingleOrDefault(x => x.Group_id == org.Organization.DocumentLibraryGroupId) ??
                            groups.Groups.SingleOrDefault(x => x.Name == orgName);

                if (group == null)
                {
                    if (org.Organization.DocumentLibraryGroupId == null)
                    {
                        continue;
                    }

                    GroupFullResult groupResult = null;

                    groupResult = this.GetGroupByName(!string.IsNullOrEmpty(groupName) ? groupName : orgName);

                    if (groupResult == null)
                    {
                        throw new Exception($"Cannot find group {orgName} in True Vault");
                    }

                    group = groupResult.Group;
                }

                groupId   = group.Group_id;
                groupName = group.Name;


                try
                {
                    this.UpdateGroup(groupId, groupName, userId);
                }
                catch
                {
                    //Ignore Exception user already exists
                }
            }
        }