示例#1
0
        public void Register(EndUserId endUserId, string?name, RobotApplication?application)
        {
            void AddRegistration()
            {
                var registrationId = new RobotRegistrationId(Guid.NewGuid());
                var e = RobotRegistered.Create(registrationId, endUserId, name, application);

                Apply(e);
                Append(registrationId.Value, RobotRegistered.EventType, e);
            }

            var latestRegistration = Registrations.LastOrDefault();

            if (latestRegistration == null)
            {
                AddRegistration();
            }
            else
            {
                latestRegistration.Apply(
                    registration => throw new ValidationException("Robot is already registered"),
                    unregistration => AddRegistration()
                    );
            }
        }
 public Registration(Robot robot, RobotImported e, Guid endUserId)
 {
     Id          = new RobotRegistrationId(Guid.NewGuid());
     EndUserId   = new EndUserId(endUserId);
     Name        = $"{robot.Product:G} - {robot.SerialNumber}";
     Application = e.Entity.GetRobotApplication();
 }
 public Registration(Robot robot, RobotRegistered e)
 {
     Id          = new RobotRegistrationId(Guid.NewGuid());
     EndUserId   = e.EndUserId;
     Name        = e.Name ?? $"{robot.Product:G} - {robot.SerialNumber}";
     Application = e.Application;
 }
 public static RobotRegistered Create(
     RobotRegistrationId registrationId,
     EndUserId endUserId,
     string?name,
     RobotApplication?application
     ) =>
 new RobotRegistered
 {
     RegistrationId = registrationId,
     EndUserId      = endUserId,
     Name           = name,
     Application    = application
 };