コード例 #1
0
ファイル: Robot.cs プロジェクト: Nillerr/EventSourcing.Demo
        public void Edit(EndUserId endUserId, string?name, RobotApplication?application)
        {
            var latestRegistration = Registrations.LastOrDefault();

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

            latestRegistration.Apply(
                registration =>
            {
                if (registration.EndUserId != endUserId)
                {
                    throw new ValidationException("Robot is registered to somebody else");
                }

                var e = RobotEdited.Create(name, application);

                Apply(e);
                Append(Guid.NewGuid(), RobotEdited.EventType, e);
            },
                unregistration => throw new ValidationException("Robot is not registered")
                );
        }
コード例 #2
0
ファイル: Robot.cs プロジェクト: Nillerr/EventSourcing.Demo
        private void Apply(RobotEdited e)
        {
            var latestRegistration = Registrations.LastOrDefault();

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

            latestRegistration.Apply(
                registration => registration.Apply(this, e),
                unregistration => throw new InvalidOperationException("Robot is not registered")
                );
        }
コード例 #3
0
 public void Apply(Robot robot, RobotEdited e)
 {
     Name        = e.Name ?? $"{robot.Product:G} - {robot.SerialNumber}";
     Application = e.Application;
 }