Ejemplo n.º 1
0
        public async Task UpdateAsync <TAccessRule, TAddOrUpdateAccessRuleCommand>(
            IEntityAccessRestrictable <TAccessRule> entity,
            UpdateAccessRuleSetCommandBase <TAddOrUpdateAccessRuleCommand> command,
            IExecutionContext executionContext
            )
            where TAccessRule : IEntityAccessRule, new()
            where TAddOrUpdateAccessRuleCommand : AddOrUpdateAccessRuleCommandBase
        {
            var accessRules = EnumerableHelper.Enumerate(command.AccessRules);
            var roles       = await GetRolesAsync(accessRules);

            var userAreas = await GetUserAreasAsync(accessRules, executionContext);

            DeleteRules(entity, accessRules);
            UpdateRules(entity, accessRules, roles, userAreas);
            AddRules(entity, accessRules, roles, userAreas, executionContext);
            UpdateEntity(entity, command, userAreas);
        }
Ejemplo n.º 2
0
        private static void UpdateEntity <TAccessRule, TAddOrUpdateAccessRuleCommand>(
            IEntityAccessRestrictable <TAccessRule> entity,
            UpdateAccessRuleSetCommandBase <TAddOrUpdateAccessRuleCommand> command,
            Dictionary <string, IUserAreaDefinition> userAreas
            )
            where TAccessRule : IEntityAccessRule
            where TAddOrUpdateAccessRuleCommand : AddOrUpdateAccessRuleCommandBase
        {
            entity.AccessRuleViolationActionId = (int)command.ViolationAction;

            if (string.IsNullOrEmpty(command.UserAreaCodeForSignInRedirect))
            {
                entity.UserAreaCodeForSignInRedirect = null;
            }
            else
            {
                var userArea = userAreas.GetOrDefault(command.UserAreaCodeForSignInRedirect);
                EntityNotFoundException.ThrowIfNull(userArea, command.UserAreaCodeForSignInRedirect);
                entity.UserAreaCodeForSignInRedirect = userArea.UserAreaCode;
            }
        }