Пример #1
0
 public void ChangePermissionByRole(RoleActionMappingChangeByRoleCommand command, out IList <RoleActionMapping> roleActionMappingsAdd, out IList <string> actionIdsRemove)
 {
     roleActionMappingsAdd = new List <RoleActionMapping>();
     actionIdsRemove       = new List <string>();
     if (command.ActionIdsRemove?.Length > 0)
     {
         foreach (var s in command.ActionIdsRemove)
         {
             RoleActionMapping roleActionMapping = Remove(command.RoleId, s);
             if (roleActionMapping != null)
             {
                 actionIdsRemove.Add(s);
             }
         }
     }
     if (command.ActionIdsAdd?.Length > 0)
     {
         foreach (var s in command.ActionIdsAdd)
         {
             RoleActionMapping roleActionMapping = Add(command.RoleId, s, string.Empty);
             if (roleActionMapping != null)
             {
                 roleActionMappingsAdd.Add(roleActionMapping);
             }
         }
     }
 }
        public async Task <ICommandResult> Handle(RoleActionMappingChangeByRoleCommand mesage)
        {
            ICommandResult result;

            try
            {
                RRole rRole = await _roleService.RoleGetByIdFromDb(mesage.RoleId);

                if (rRole == null)
                {
                    result = new CommandResult
                    {
                        Message  = "Role not found.",
                        ObjectId = string.Empty,
                        Status   = CommandResult.StatusEnum.Fail
                    };
                    return(result);
                }
                RRoleActionMapping[] roleActionMappings =
                    await _roleService.RoleActionMappingGetByRoleIdFromDb(mesage.RoleId);

                Role role = new Role(rRole, roleActionMappings);
                role.ChangePermissionByRole(mesage, out var roleActionMappingsAdd, out var actionIdsRemove);

                await _roleService.ChangeToDb(roleActionMappingsAdd.ToArray(), mesage.RoleId, actionIdsRemove.ToArray());

                await _eventSender.Notify(role.Events);

                result = new CommandResult
                {
                    Message  = "",
                    ObjectId = role.Id,
                    Status   = CommandResult.StatusEnum.Sucess
                };
                return(result);
            }
            catch (Exception e)
            {
                e.Data["Param"] = mesage;
                result          = new CommandResult()
                {
                    Message = e.Message,
                    Status  = CommandResult.StatusEnum.Fail
                };
                return(result);
            }
        }
Пример #3
0
 public async Task <CommandResult> SendCommand(RoleActionMappingChangeByRoleCommand command)
 {
     return(await _commandService.SendAndReceiveResult <CommandResult>(command));
 }