示例#1
0
        public void Unregister(EndUserId endUserId)
        {
            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                throw new ValidationException("Robot is not registered");
            }

            latestRegistration.Apply(
                registration =>
            {
                if (registration.EndUserId == endUserId)
                {
                    var e = RobotUnregistered.Create();
                    Apply(e);
                    Append(Guid.NewGuid(), RobotUnregistered.EventType, e);
                }
                else
                {
                    throw new ValidationException("Robot is registered to somebody else");
                }
            },
                unregistration => throw new ValidationException("Robot is not registered")
                );
        }
示例#2
0
        private void Apply(RobotUnregistered e)
        {
            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                throw new InvalidOperationException("Robot is not already registered");
            }

            latestRegistration.Apply(
                registration => { Registrations = Registrations.Add(RobotRegistration.Unregistration.Instance); },
                unregistration => throw new InvalidOperationException("Robot is not already registered")
                );
        }