public IApuxActionResult Dispatch(ApuxAction <JToken> actionRequest)
        {
            switch (actionRequest.Type)
            {
            case CartActions.LIST_PRODUCTS:
            {
                return(_cartActionHandler.ListProductsHandler(new ListProductsAction()));
            }

            case CartActions.ADD_PRODUCT:
            {
                return(_cartActionHandler.AddProductHandler(new AddProductAction(actionRequest.Payload)));
            }

            case CartActions.REMOVE_PRODUCT:
            {
                return(_cartActionHandler.RemoveProductHandler(new RemoveProductAction(actionRequest.Payload)));
            }

            case CartActions.GET_TOTAL_PRICE:
            {
                return(_cartActionHandler.GetProductTotalPriceHandler(new GetTotalPriceAction()));
            }

            default:
            {
                return(_appErrorActionHandler.UnknownActionHandler(new UnknownActionAction()));
            }
            }
        }
        public IApuxActionResult Dispatch(string actionNamespace, ApuxAction <JToken> action)
        {
            // set app error as default action dispatch
            IApuxActionResult result = _appErrorActions.Dispatch(action);

            switch (actionNamespace)
            {
            // App error actions
            case Constants.ActionNamespace.APP:
            {
                result = _appErrorActions.Dispatch(action);
            }
            break;

            // Cart actions
            case Constants.ActionNamespace.CART:
            {
                result = _cartActionDispatcher.Dispatch(action);
            }
            break;

            // Product actions
            case Constants.ActionNamespace.PRODUCT:
            {
                result = _productActions.Dispatch(action);
            }
            break;
            }

            return(result);
        }
Example #3
0
        public IApuxActionResult Dispatch(ApuxAction <JToken> actionRequest)
        {
            switch (actionRequest.Type)
            {
            case ProductActions.GET_ALL:
            {
                return(_productActionHandler.GetAll(new GetAllAction(actionRequest.Payload)));
            }

            case ProductActions.GET_BY_ID:
            {
                return(_productActionHandler.GetById(new GetByIdAction(actionRequest.Payload)));
            }

            case ProductActions.UPDATE:
            {
                return(_productActionHandler.Update(new UpdateAction(actionRequest.Payload)));
            }

            default:
            {
                return(_appErrorActionHandler.UnknownActionHandler(new UnknownActionAction()));
            }
            }
        }
Example #4
0
        public IApuxActionResult Dispatch(ApuxAction <JToken> actionRequest)
        {
            switch (actionRequest.Type)
            {
            case AppErrorActions.INTERNAL_ERROR:
            {
                return(_appErrorActionHandler.InternalErrorActionHandler(new InternalErrorAction()));
            }

            case AppErrorActions.UNKNOWN_ACTION:
            default:
            {
                return(_appErrorActionHandler.UnknownActionHandler(new UnknownActionAction()));
            }
            }
        }
        public IApuxActionResult RootDispatch(IApuxAction actionRequest)
        {
            // Get action namespace
            var actionNamespace = actionRequest.Type.Split(Constants.ACTION_NAMESPACE_SEPERATOR)[0];
            // instantiate a new action for the request
            var action = new ApuxAction <JToken>(actionRequest.Type, JToken.FromObject(actionRequest.BasePayload));

            // dispatch to child dispatchers using namespace
            IApuxActionResult result = Dispatch(actionNamespace, action);

            // recursively dispatch any returned actions (allows chaining of dispatch actions)
            if (result.Dispatch)
            {
                result = RootDispatch(result);
            }

            return(result);
        }