예제 #1
0
        private void ChangeState(CustomerState dest)
        {
            var command = GetCommand(CustomerTransition.Create(State, dest));

            if (command == null)
            {
                throw new Exception($"Command is null for {State} -> {dest}");
            }
            command.Execute();
        }
예제 #2
0
        public CustomerService()
        {
            RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New),
                               new UndefinedToNewCommand());

            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed),
                               new NewToConfirmedCommand());


            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed),
                               new NewToUnconfirmedCommand());
        }
예제 #3
0
        public void ChangeStateToUnconfirmed()
        {
            var transition = new CustomerTransition(State, CustomerState.Unconfirmed);

            if (!HasTransition(transition))
            {
                throw new InvalidOperationException(transition.ToString());
            }

            if (DocumentsSigned)
            {
                throw new Exception("Documents are signed!");
            }

            State = CustomerState.Unconfirmed;
        }
예제 #4
0
        public Customer(Guid customerId)
        {
            CustomerId = customerId;
            State      = CustomerState.Undefined;


            RegisterTransition(CustomerTransition.Create(CustomerState.Undefined, CustomerState.New),
                               new UndefinedToNewCommand(this));

            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Confirmed),
                               new NewToConfirmedCommand(this));


            RegisterTransition(CustomerTransition.Create(CustomerState.New, CustomerState.Unconfirmed),
                               new NewToUnconfirmedCommand(this));

            ChangeStateToNew();
        }
예제 #5
0
        private void ChangeState(Customer customer, CustomerState dest)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }


            var command = GetCommand(CustomerTransition.Create(customer.State, dest));

            if (command == null)
            {
                throw new Exception($"Command is null for {customer.State} -> {dest}");
            }
            var baseCustomerCommand = (BaseCustomerCommand)command;

            baseCustomerCommand.SetCustomer(customer);
            command.Execute();
        }