public async Task <FormComponentModel> BuildCreateFormModelAsync(Guid siteId)
        {
            var result = new FormComponentModel();

            foreach (var roleModel in await _roleManager.GetRoleModelsAsync())
            {
                var permissionModel = new FormComponentModel.PermissionModel
                {
                    RoleId   = roleModel.Id,
                    RoleName = roleModel.Name
                };

                foreach (PermissionType permissionType in Enum.GetValues(typeof(PermissionType)))
                {
                    var disabled = roleModel.Name == Consts.RoleNameAdmin ||
                                   roleModel.Id == Consts.RoleIdAll && !IsReadingPermissionType(permissionType);

                    permissionModel.PermissionTypes.Add(new FormComponentModel.PermissionTypeModel
                    {
                        Type     = permissionType,
                        Selected = roleModel.Name == Consts.RoleNameAdmin,
                        Disabled = disabled
                    });
                }

                result.PermissionSet.Permissions.Add(permissionModel);
            }

            return(result);
        }
        public async Task <FormComponentModel> BuildEditFormModelAsync(Guid siteId, Guid id)
        {
            var result = new FormComponentModel();

            var permissionSet = await _dbContext.PermissionSets
                                .Include(x => x.Permissions)
                                .FirstOrDefaultAsync(x =>
                                                     x.SiteId == siteId &&
                                                     x.Id == id &&
                                                     x.Status != PermissionSetStatusType.Deleted);

            if (permissionSet == null)
            {
                return(null);
            }

            result.PermissionSet = new FormComponentModel.PermissionSetModel
            {
                Id   = permissionSet.Id,
                Name = permissionSet.Name
            };

            foreach (var roleModel in await _roleManager.GetRoleModelsAsync())
            {
                var permissionModel = new FormComponentModel.PermissionModel
                {
                    RoleId   = roleModel.Id,
                    RoleName = roleModel.Name
                };

                foreach (PermissionType permissionType in Enum.GetValues(typeof(PermissionType)))
                {
                    var selected = permissionSet.Permissions
                                   .FirstOrDefault(x => x.Type == permissionType &&
                                                   x.RoleId == roleModel.Id) != null ||
                                   roleModel.Name == Consts.RoleNameAdmin;

                    var disabled = roleModel.Name == Consts.RoleNameAdmin ||
                                   roleModel.Id == Consts.RoleIdAll && !IsReadingPermissionType(permissionType);

                    permissionModel.PermissionTypes.Add(new FormComponentModel.PermissionTypeModel
                    {
                        Type     = permissionType,
                        Selected = selected,
                        Disabled = disabled
                    });
                }

                result.PermissionSet.Permissions.Add(permissionModel);
            }

            return(result);
        }