Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request.QueryString["action"];

            if (!CommonLogic.IsStringNullOrEmpty(action))
            {
                IActionHandler handler = ActionHandlerFactory.GetHandler(action);
                if (null != handler)
                {
                    handler.Handle(context);
                }
            }
        }
        public Result <Order> CompleteOrder(Cart cart)
        => _actionHandler.Handle <Order>(() =>
        {
            Console.WriteLine("Processing an order...");
            User user   = _database.Users.GetById(cart.UserId);
            int orderId = _database.Orders.Any() ? _database.Orders.Max(x => x.Id) + 1 : 1;
            Order order = new Order(orderId);
            foreach (CartItem item in cart.Items)
            {
                Product product = _database.Products.GetById(item.ProductId);
                order.AddProduct(product, item.Quantity);
            }
            user.PurchaseOrder(order);
            _database.SaveChanges();

            return(order);
        },
                                         ex => Console.WriteLine("Ther was an error when processing an order."));
Ejemplo n.º 3
0
        public ApiAiFulfillmentResponse Post([FromBody] ApiAiFulfillmentRequest request)
        {
            try
            {
                _log.LogInformation("Received fulfillment request.");
                _log.LogInformation("Intent is " + request.Result.Metadata.IntentName);

                ApiContextToAdvContext(request);

                _handler.Handle();

                _log.LogInformation("Creating response...");
                _log.LogInformation(_advContext.SpeechResponse);
                var response = new ApiAiFulfillmentResponse
                {
                    Speech      = _advContext.SpeechResponse,
                    DisplayText = _advContext.TextResponse,
                    Source      = "apiWebhook",
                    //Data = "",
                    ContextOut = new[]
                    {
                        AdvContextToApiContext()
                    },
                    //FollowupEvent = ""
                };
                _log.LogInformation("Sending response...");
                return(response);
            }
            catch (Exception ex)
            {
                _log.LogError(ex.Message);
                return(new ApiAiFulfillmentResponse
                {
                    Speech = ex.Message,
                    DisplayText = ex.Message
                });
            }
        }
Ejemplo n.º 4
0
    public void Process(SomeDto dto)
    {
        IActionHandler actionHanlder = this.strategyResolver.Resolve <IActionHandler>(dto.SomeProperty);

        actionHanlder.Handle(dto);
    }