示例#1
0
        //
        // GET: /Checkout/Complete
        public async Task <IActionResult> Complete(
            [FromServices] IOrderProcessing orders,
            int id)
        {
            var userName = HttpContext.User.Identity.Name;

            // Validate customer owns this order
            var order = await orders.GetOrderAsync(id);

            bool isValid = order != null && order.Username.Equals(userName);

            if (isValid)
            {
                _logger.LogInformation("User {userName} completed checkout on order {orderId}.", userName, id);
                return(View(id));
            }
            else
            {
                _logger.LogError(
                    "User {userName} tried to checkout with an order ({orderId}) that doesn't belong to them.",
                    userName,
                    id);
                return(View("Error"));
            }
        }
 private ShoppingCart(IShoppingCart shoppingCart, IMusicStore musicStore, IOrderProcessing orderProcessing, string id)
 {
     _shoppingCart    = shoppingCart;
     _musicStore      = musicStore;
     _orderProcessing = orderProcessing;
     _shoppingCartId  = id;
 }
示例#3
0
        static void CallViaInterface()
        {
            IOrderProcessing client = null;

            try
            {
                Console.WriteLine("About to invoke OrderProcessing service");

                WSHttpBinding binding = new WSHttpBinding(
                    "WSHttpBinding_IOrderProcessing");
                EndpointAddress epAddr = new EndpointAddress(
                    "http://*****:*****@foo.com";
                request.TotalAmount          = 75.00M;
                request.Items = new List <Item>
                {
                    new Item {
                        ItemId = 1234, Quantity = 1
                    },
                    new Item {
                        ItemId = 2345, Quantity = 3
                    },
                };

                ProcessOrderResponse poResponse = client.ProcessOrder(
                    new ProcessOrderRequest(request));

                OrderProcessingResponse response =
                    poResponse.OrderProcessingResponse;

                Console.WriteLine("Response IsSuccessful: {0}",
                                  response.IsSuccessful);
                Console.WriteLine("Response OrderId: {0}",
                                  response.OrderId);
                Console.WriteLine("Response ShipDate: {0:D}",
                                  response.ShipDate);
                Console.WriteLine("Response CreditAuthCode: {0}",
                                  response.CreditAuthCode);
            }
            catch (Exception exception)
            {
                Console.WriteLine("Unhandled exception: {0}", exception.Message);
            }
            finally
            {
                ((IChannel)client).Close();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            string      baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host        = new ServiceHost(typeof(OrderProcessingService), new Uri(baseAddress));

            host.AddServiceEndpoint(typeof(IOrderProcessing), new BasicHttpBinding(), "");
            host.Open();
            Console.WriteLine("Host opened");

            ChannelFactory <IOrderProcessing> factory = new ChannelFactory <IOrderProcessing>(new BasicHttpBinding(), new EndpointAddress(baseAddress));
            IOrderProcessing proxy = factory.CreateChannel();
            Order            order = proxy.GetOrder(1);

            proxy.ProcessOrder(order);

            ((IClientChannel)proxy).Close();
            factory.Close();
            host.Close();
        }
示例#5
0
        public async Task <IActionResult> AddressAndPayment(
            [FromServices] IMusicStore musicStore,
            [FromServices] IOrderProcessing orders,
            [FromServices] IShoppingCart shoppingCart,
            [FromForm] Order order,
            CancellationToken requestAborted)
        {
            if (!ModelState.IsValid)
            {
                return(View(order));
            }

            var formCollection = await HttpContext.Request.ReadFormAsync();

            try
            {
                if (string.Equals(formCollection["PromoCode"].FirstOrDefault(), PromoCode,
                                  StringComparison.OrdinalIgnoreCase) == false)
                {
                    return(View(order));
                }
                else
                {
                    order.Username  = HttpContext.User.Identity.Name;
                    order.OrderDate = DateTime.Now;

                    //Process the order
                    var cart    = ShoppingCart.GetCart(shoppingCart, musicStore, orders, HttpContext);
                    int orderId = await cart.CreateOrderAsync(order);

                    _logger.LogInformation("User {userName} started checkout of {orderId}.", order.Username, order.OrderId);

                    return(RedirectToAction("Complete", new { id = orderId }));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                //Invalid - redisplay with errors
                return(View(order));
            }
        }
示例#6
0
 public OrderController(IOrderProcessing orders)
 {
     this.orders = orders;
 }
 public void SetOrderProcessing(IOrderProcessing orderProcessing)
 {
     _orderProcessing = orderProcessing;
 }
示例#8
0
 public BussinessruleController(IOrderProcessing <BookModel> ibookserv)
 {
     _ibookserv = ibookserv;
 }
 public static ShoppingCart GetCart(IShoppingCart shoppingCart, IMusicStore musicStore, IOrderProcessing orderProcessing, string cartId)
 => new ShoppingCart(shoppingCart, musicStore, orderProcessing, cartId);
 public static ShoppingCart GetCart(IShoppingCart shoppingCart, IMusicStore musicStore, IOrderProcessing orderProcessing, HttpContext context)
 => GetCart(shoppingCart, musicStore, orderProcessing, GetCartIdAsync(shoppingCart, context).Result);
 public CartController(IDishesRepository repo, IOrderProcessing orderProcess)
 {
     this.repository = repo;
     orderProcessing = orderProcess;
 }