private void SaleReturnOrderTransitionFromInitState(OrderStateMachine stateMachine, State <OrderCarrier> returnConfirmed) { //build SRO state transitions. //From Init to ReturnConfirmed. stateMachine.AddStateTransition(new State <OrderCarrier>((short)OrderState.Init, OrderState.Init.ToString()), returnConfirmed, (orderCarrier, startState, endState, token) => { //Conditions for SRO from init to ReturnConfirmed. //Precodition: //+RMA in Completed state and it should be Approved //+Order is of type SalesReturnOrder if (orderCarrier.Type != OrderType.SalesReturnOrder || orderCarrier.RmaSystemId is null || orderCarrier.RmaSystemId == Guid.Empty) { return(false); } var rma = _rmaService.Get(orderCarrier.RmaSystemId.Value); //RmaState.Completed denote that the Rma process is completed, the ApprovateCode.Approved denote that it actually is approved. return(rma?.State == RmaState.Completed && rma?.ApprovalCode == ApprovalCode.Approved); },
/// <summary> /// Builds the order states. /// </summary> /// <param name="stateMachine">The state machine.</param> public virtual void Build(OrderStateMachine stateMachine) { //Order is placed, but waiting confirmation. var waitingConfirmation = new State <OrderCarrier>((short)OrderState.WaitingConfirmation, OrderState.WaitingConfirmation.ToString()); //Order Confirmed var confirmed = new State <OrderCarrier>((short)OrderState.Confirmed, OrderState.Confirmed.ToString(), (orderCarrier, currentState, token) => { //Order confirmed entry action. //now the order is confirmed, reduce the stock balances. _orderUtilities.ReduceStockBalance(ModuleECommerce.Instance.Orders[orderCarrier.ID, token], ModuleECommerce.Instance.AdminToken); //notify campaigns engine to take order confirmation actions. ModuleECommerce.Instance.CampaignCalculator.HandleOrderConfirmation(orderCarrier, ModuleECommerce.Instance.AdminToken); //Send order confirmation email. _mailService.SendEmail(new OrderConfirmationEmail(orderCarrier.ChannelID, orderCarrier.ID, orderCarrier.CustomerInfo.Address.Email), false); //TODO: integration code to execute when an order is confirmed. //.... }, null); //Order Processing: Order has started processing. e.g. delivery packages are being processed. var processing = new State <OrderCarrier>((short)OrderState.Processing, OrderState.Processing.ToString()); //Order Completed: All tasks relating to order is completed. var completed = new State <OrderCarrier>((short)OrderState.Completed, OrderState.Completed.ToString()); //Order Returned:order is returned. var returned = new State <OrderCarrier>((short)OrderState.Returned, OrderState.Returned.ToString()); //Order Attention: requires administrators attention. var attention = new State <OrderCarrier>((short)OrderState.Attention, OrderState.Attention.ToString()); //Order ClosedByAdmin: order is closed by administrator. var closedByAdmin = new State <OrderCarrier>((short)OrderState.ClosedByAdmin, OrderState.ClosedByAdmin.ToString()); //Order Cancelled: order is Cancelled either by end customer or administrator. var cancelled = new State <OrderCarrier>((short)OrderState.Cancelled, OrderState.Cancelled.ToString()); //ReturnManagement State - These are new states for SaleReturnOrder only // Rma is approved and the return is confirmed, this is the innitial status of Sales return order var returnConfirmed = new State <OrderCarrier>((short)OrderState.ReturnConfirmed, OrderState.ReturnConfirmed.ToString(), (orderCarrier, currentState, token) => { //TODO: integration code to execute when a sales return order is registered. //TODO: send a returned items acceptance email to the end-customer. }, null); // Sales return order is in processing. var returnProcessing = new State <OrderCarrier>((short)OrderState.ReturnProcessing, OrderState.ReturnProcessing.ToString()); // Sales return order is now completed. var returnCompleted = new State <OrderCarrier>((short)OrderState.ReturnCompleted, OrderState.ReturnCompleted.ToString()); //build state transitions. TransitionsFromInitState(stateMachine, waitingConfirmation, cancelled); TransitionsFromWaitingConfirmationState(stateMachine, waitingConfirmation, confirmed, cancelled); TransitionsFromConfirmedState(stateMachine, confirmed, processing, cancelled); TransitionsFromProcessingState(stateMachine, processing, completed, attention, cancelled); TransitionsFromCompletedState(stateMachine, completed, returned, attention); TransitionsFromAttentionState(stateMachine, completed, returned, attention, closedByAdmin, cancelled); stateMachine.AddStateTransition(closedByAdmin, attention); //state transitions for Sale Return Order SaleReturnOrderTransitionFromInitState(stateMachine, returnConfirmed); SaleReturnOrderTransitionFromReturnConfirmed(stateMachine, returnConfirmed, returnProcessing); SaleReturnOrderTransitionFromReturnProcessing(stateMachine, returnProcessing, returnCompleted); }