示例#1
0
        public Order(OrderDataEntity orderDataEntity)
        {
            this.orderDataEntity = orderDataEntity;

            enumConverter = new EnumConverter();
            var initialState = enumConverter.ToEnum <State>(orderDataEntity.State);

            machine = new StateMachine <State, Trigger>(initialState);

            machine.Configure(State.New).Permit(Trigger.Process, State.Processing);
            machine.Configure(State.Processing)
            .OnEntry(() => {
                this.orderDataEntity.State = State.Processing.ToString();
            })
            .Permit(Trigger.Send, State.Sent);
            machine.Configure(State.Sent)
            .OnEntry(() => {
                this.orderDataEntity.State = State.Sent.ToString();
            })
            .Permit(Trigger.Complete, State.Completed)
            .Permit(Trigger.Reject, State.Rejected);
            machine.Configure(State.Completed)
            .OnEntry(() =>
            {
                this.orderDataEntity.State = State.Completed.ToString();
            });
            machine.Configure(State.Rejected)
            .OnEntry(() =>
            {
                this.orderDataEntity.State = State.Rejected.ToString();
            });
        }
示例#2
0
        public Mobile Cease(Guid id)
        {
            var mobile = this.mobileRepository.GetById(id);

            if (mobile == null)
            {
                logger.LogWarning("Attempt to Cease an unknown Mobile - MobileId: {MobileId}", id);
                return(null);
            }

            var newStateName = Order.State.New.ToString();
            var orderType    = Order.OrderType.Cease.ToString();
            var dataEntity   = new OrderDataEntity()
            {
                GlobalId = this.guidCreator.Create(),
                State    = newStateName,
                Type     = orderType
            };

            var inProgressOrder = new Order(dataEntity);

            mobile.Cease(inProgressOrder);
            mobileRepository.Update(mobile);

            return(mobile);
        }
        public void AddOrder(OrderDataEntity orderDataEntity)
        {
            if (this.Orders == null)
            {
                this.Orders = new List <OrderDataEntity>();
            }

            this.Orders.Add(orderDataEntity);
        }
        public MobileWhenNewBuilder AddInProgressOrder(OrderToAdd order, Guid orderGlobalId)
        {
            var newStateName = new EnumConverter().ToName <MobileState>(MobileState.New);
            var dataEntity   = new OrderDataEntity()
            {
                GlobalId           = orderGlobalId,
                Name               = order.Name,
                ContactPhoneNumber = order.ContactPhoneNumber,
                State              = newStateName,
                Type               = this.enumConverter.ToName <Order.OrderType>(Order.OrderType.Provision)
            };

            orders.Add(new Order(dataEntity));

            return(this);
        }