public OrdersMutation(IOrderServices orderService)
        {
            Name = "Mutations";

            Field <OrderGraphType>(
                "createOrder",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <OrderCreateInputType> >()
            {
                Description = "Order Input description sample",
                Name        = "order"
            }), resolve: context =>
            {
                var inputOrder = context.GetArgument <OrderCreateInput>("order");
                var guid       = Guid.NewGuid().ToString();
                var order      = new Order(inputOrder.Name, inputOrder.Description,
                                           inputOrder.Created, inputOrder.CustomerId, guid);

                return(orderService.CreateAsync(order));
            });

            FieldAsync <OrderGraphType>(
                "startOrder",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> >()
            {
                Name = "orderId"
            }), resolve: async context =>
            {
                var inputOrderId = context.GetArgument <string>("orderId");

                return(await context.TryAsyncResolve(
                           async c => await orderService.StartAsync(inputOrderId)));
            });
        }
Beispiel #2
0
        public async Task <PartialViewResult> ShoppingCart()
        {
            Order order = new Order();

            // Check cart exist
            int?baseId = (Session["Account"] as Account)?.AccountId;
            var cart   = await _order.FindAsync(x => x.AccountId == baseId && x.Status == OrderStatus.InCart);

            if (cart != null)
            {
                order = cart;
            }
            else
            {
                order.AccountId = baseId;
                order.Status    = OrderStatus.InCart;
                await _order.CreateAsync(order);
            }

            return(PartialView("_ShoppingCart", order));
        }