public async Task Create([FromBody] CreateGroup body)
        {
            var groupId = $"{SpisumNames.Prefixes.Group}{body.Id}";

            try
            {
                var permissions = Enum.GetValues(typeof(GroupPermissionTypes)).Cast <GroupPermissionTypes>().Select(x => $"_{x}").ToList();
                permissions.Insert(0, "");                   // for basic name, for list all people in
                permissions.Add(SpisumNames.Postfixes.Sign); // for getting people who can sign

                foreach (var permission in permissions)
                {
                    await _alfrescoHttpClient.CreateGroup(new GroupBodyCreate
                    {
                        Id          = $"{groupId}{permission}",
                        DisplayName = $"{body.Name}{permission}"
                    });
                }

                // add to main group
                await _initialGroup.AddMainGroupMember(SpisumNames.Groups.MainGroup, groupId);

                if (body.Type?.ToLower() == "dispatch")
                {
                    await _initialGroup.AddMainGroupMember(SpisumNames.Groups.DispatchGroup, groupId);
                }
                else if (body.Type?.ToLower() == "repository")
                {
                    await _initialGroup.AddMainGroupMember(SpisumNames.Groups.RepositoryGroup, groupId);
                }

                await _initScript.ProcessGroup(groupId);
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Create group structure failed");
                await _alfrescoHttpClient.DeleteGroup(groupId);
            }
        }
        public async Task Init()
        {
            if (_initiated)
            {
                return;
            }
            _initiated = true;

            var configGroups = _alfrescoConfig?.Groups != null
                ? JsonConvert.DeserializeObject <List <GroupModel> >(File.ReadAllText(_alfrescoConfig.Groups))
                : new List <GroupModel>();

            var configRoles = _alfrescoConfig?.Roles != null
                ? JsonConvert.DeserializeObject <List <GroupBodyCreate> >(File.ReadAllText(_alfrescoConfig.Roles))
                : new List <GroupBodyCreate>();

            var permissions = Enum.GetValues(typeof(GroupPermissionTypes)).Cast <GroupPermissionTypes>().Select(x => $"_{x}").ToList();

            permissions.Insert(0, "");                   // for basic name, for list all people in
            permissions.Add(SpisumNames.Postfixes.Sign); // for getting people who can sign

            var groups = configGroups.Select(x => x.Body).ToList();

            // mandatory groups
            groups.Insert(0, new GroupBodyCreate {
                Id = SpisumNames.Groups.DispatchGroup, DisplayName = "Výpravna"
            });
            groups.Insert(0, new GroupBodyCreate {
                Id = SpisumNames.Groups.MailroomGroup, DisplayName = "Podatelna"
            });
            groups.Insert(0, new GroupBodyCreate {
                Id = SpisumNames.Groups.RepositoryGroup, DisplayName = "Spisovna"
            });

            // custom groups
            foreach (var group in groups)
            {
                foreach (var permission in permissions)
                {
                    await CreateGroup(new GroupBodyCreate { Id = $"{group.Id}{permission}", DisplayName = $"{group.DisplayName}{permission}" });
                }
            }

            // system groups
            var systemGroups = new List <GroupBodyCreate>
            {
                new GroupBodyCreate {
                    Id = SpisumNames.Groups.SpisumAdmin, DisplayName = SpisumNames.Groups.SpisumAdmin
                },
                new GroupBodyCreate {
                    Id = SpisumNames.Groups.MainGroup, DisplayName = SpisumNames.Groups.MainGroup
                },
                new GroupBodyCreate {
                    Id = SpisumNames.Groups.RolesGroup, DisplayName = "Role"
                }
            };

            foreach (var group in systemGroups)
            {
                await CreateGroup(new GroupBodyCreate { Id = group.Id, DisplayName = group.DisplayName });
            }

            foreach (var role in configRoles)
            {
                await CreateGroup(role);

                await _initialGroup.AddMainGroupMember(SpisumNames.Groups.RolesGroup, role.Id);
            }

            // add all groups to main group for access
            foreach (var group in groups.Where(x => Array.IndexOf(new[] {
                SpisumNames.Groups.DispatchGroup,
                SpisumNames.Groups.MainGroup,
                SpisumNames.Groups.RolesGroup,
                SpisumNames.Groups.RepositoryGroup,
                SpisumNames.Groups.SpisumAdmin
            }, x.Id) == -1))
            {
                await _initialGroup.AddMainGroupMember(SpisumNames.Groups.MainGroup, group.Id);
            }

            // add all repository groups
            foreach (var group in configGroups.Where(x => x.IsRepository == true))
            {
                await _initialGroup.AddMainGroupMember(SpisumNames.Groups.RepositoryGroup, group.Body.Id);
            }

            // add all dispatch groups
            foreach (var group in configGroups.Where(x => x.IsDispatch == true))
            {
                await _initialGroup.AddMainGroupMember(SpisumNames.Groups.DispatchGroup, group.Body.Id);
            }
        }