Exemplo n.º 1
0
        public async Task <UserDTO> Handle(UserPermissionsRequestedCommand command)
        {
            var forAgg = await _session.Get <UserAggregate>(command.Input.ForId);

            var byAgg = await _session.Get <UserAggregate>(command.Input.ById);

            command.Input.Requests = VerifyActions(
                forAgg,
                byAgg,
                command.Input.Requests,
                new List <string> {
                typeof(UserPermissionsRequestedEvent).FullName, typeof(UserPermissionGrantedEvent).FullName
            });

            if (command.Input.Requests.Any())
            {
                var permissionAggregates = new List <PermissionAggregate>();
                foreach (var request in command.Input.Requests)
                {
                    permissionAggregates.Add(await _session.Get <PermissionAggregate>(request.Key));
                }

                forAgg.UserRequestedPermissions(permissionAggregates, command.Input);
                await _session.Commit();

                _email.SendPermissionsRequestedMessage(forAgg, permissionAggregates);
            }
            return(_mapper.Map <UserDTO>(forAgg));
        }