//helpful function dont know if this is the right place for it
        public static void AddUserPermission(UserData addto, UserPermission from)
        {
            if (from.AssignedUsers == null)
            {
                return;
            }
            addto._permission = Permission.SelectPermission(from.AccessPermission);
            addto._user_email = from.AssignedUsers.MailAddress;
            string tmp = "";

            //add all roles up to one string
            if (from.AssignedUsers.IndustryRoles != null)
            {
                for (int i = 0; i < from.AssignedUsers.IndustryRoles.Count; i++)
                {
                    if (i != 0)
                    {
                        tmp += ",";
                    }

                    tmp += from.AssignedUsers.IndustryRoles[i];
                }

                addto._industry_role = tmp;
            }

            if (from.AssignedUsers.AssignedCompany != null)
            {
                addto._company       = from.AssignedUsers.AssignedCompany.Name;
                addto._company_trade = SelectionManager.SelectTrade(from.AssignedUsers.AssignedCompany.Trade);
            }
        }
        ///<summary>
        ///
        /// </summary>
        public static List <UserData> ExportBim360ToCSV(List <Bim360Project> input)
        {
            List <UserData> output = new List <UserData>();

            //iterate over all BimProjects
            foreach (var iter in input)
            {
                //add new Row in the "CSV"
                output.Add(new UserData());
                var activeRow = output.Last();
                activeRow._project_name = iter.ProjectName;

                //add projectTypes
                activeRow._project_type = SelectionManager.SelectProjectType(iter.ProjectType);

                //user on Project level
                foreach (var useriter in iter.superuser)
                {
                    activeRow._user_email = useriter.MailAddress;
                    if (useriter.AssignedCompany != null)
                    {
                        activeRow._company       = useriter.AssignedCompany.Name;
                        activeRow._company_trade = SelectionManager.SelectTrade(useriter.AssignedCompany.Trade);
                    }
                    //Add IndustryRoles
                    string tmp = "";
                    if (useriter.IndustryRoles != null)
                    {
                        for (int i = 0; i < useriter.IndustryRoles.Count; i++)
                        {
                            if (i != 0)
                            {
                                tmp += ",";
                            }

                            tmp += useriter.IndustryRoles[i];
                        }

                        activeRow._industry_role = tmp;
                    }

                    output.Add(new UserData());
                    activeRow = output.Last();
                }


                //Add folder structure under Plans
                //Hardcoded for Plans & Projcet Files
                activeRow._root_folder  = "Plans";
                activeRow._local_folder = iter.Plans.SampleFilesDirectory;

                //add User permissions
                foreach (var iterperm in iter.Plans.UserPermissions)
                {
                    AddUserPermission(activeRow, iterperm);
                    output.Add(new UserData());
                    activeRow = output.Last();
                }
                //add role permissions
                foreach (var iterperm in iter.Plans.RolePermissions)
                {
                    activeRow._permission      = Permission.SelectPermission(iterperm.AccessPermission);
                    activeRow._role_permission = iterperm.Role;
                    output.Add(new UserData());
                    activeRow = output.Last();
                }

                //if no permission is inserted ->add new row for new Folder
                if (!iter.Plans.UserPermissions.Any() && !iter.Plans.RolePermissions.Any())
                {
                    activeRow = output.Last();
                }


                //add subfolder for Plans
                foreach (var subfolder in iter.Plans.Subfolders)
                {
                    AddAllSubFolder(output, subfolder);
                }
                //error Handling adding somewhere in Addallsubfolder a unused rowe
                if (iter.Plans.Subfolders.Count != 0)
                {
                    output.Remove(output.Last());
                }

                //Add folder structure under Project Files
                output.Add(new UserData());
                activeRow = output.Last();

                activeRow._root_folder  = "Project Files";
                activeRow._local_folder = iter.Plans.SampleFilesDirectory;

                //add User permissions
                foreach (var iterperm in iter.ProjectFiles.UserPermissions)
                {
                    AddUserPermission(activeRow, iterperm);
                    output.Add(new UserData());
                    activeRow = output.Last();
                }
                //add role permissions
                foreach (var iterperm in iter.ProjectFiles.RolePermissions)
                {
                    activeRow._permission      = Permission.SelectPermission(iterperm.AccessPermission);
                    activeRow._role_permission = iterperm.Role;
                    output.Add(new UserData());
                    activeRow = output.Last();
                }

                //if no permission is inserted ->add new row for new Folder
                if (!iter.ProjectFiles.UserPermissions.Any() && !iter.ProjectFiles.RolePermissions.Any())
                {
                    activeRow = output.Last();
                }


                //add subfolder
                foreach (var subfolder in iter.ProjectFiles.Subfolders)
                {
                    AddAllSubFolder(output, subfolder);
                }
                //error Handling adding somewhere in Addallsubfolder a unused rowe
                if (iter.ProjectFiles.Subfolders.Count != 0)
                {
                    output.Remove(output.Last());
                }

                //Create an empty row
                output.Add(new UserData());
            }


            return(output);
        }