Пример #1
0
        public async Task <UserDTO> Handle(DenyUserPermissionRequestCommand command)
        {
            var forAgg = await _session.Get <UserAggregate>(command.Input.ForId);

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

            command.Input.PermissionsToDeny = VerifyActions(
                forAgg,
                byAgg,
                command.Input.PermissionsToDeny,
                new List <string>
            {
                typeof(UserPermissionRevokedEvent).FullName,
                typeof(UserPermissionRequestDeniedEvent).FullName,
                typeof(UserPermissionGrantedEvent).FullName
            });
            if (command.Input.PermissionsToDeny.Any())
            {
                var permissionAggregates = new List <PermissionAggregate>();
                foreach (var request in command.Input.PermissionsToDeny)
                {
                    permissionAggregates.Add(await _session.Get <PermissionAggregate>(request.Key));
                }
                forAgg.DenyPermissionRequest(byAgg, permissionAggregates, command.Input);
                await _session.Commit();

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