Ejemplo n.º 1
0
        public void TestClear()
        {
            addAllItems();
            Checkout c = new Checkout(itemRepository);

            c.Scan("C");
            Assert.AreEqual(20, c.GetTotalPrice());
            c.Scan("B");
            Assert.AreEqual(50, c.GetTotalPrice());
            c.Clear();
            Assert.AreEqual(0, c.GetTotalPrice());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Run all <see cref="ArticleItemDataModel"/> in <see cref="Checkout"/> as purchase and add to database
        /// </summary>
        /// <param name="args"></param>
        private async void PurchaseCheckoutItemsAction(object args)
        {
            var    repo   = new Library.Repository.OrdersRepository("Orders");
            string result = "Something went wrong";

            // Datauppkoppling och spara data som finns i Checkout
            Order order = new Order {
                CustomerID  = 1337,
                Orderstatus = 1,
                Price       = CheckOutSum,
                Articles    = new List <Article>(),
                //System.DateTime.Now.ToString("yy-MM-dd hh:mm:ss")
                TimeCreated = System.DateTime.Now,
            };

            foreach (var articleDataModel in Checkout)
            {
                // Deconstruct into Article
                Article newArticle = articleDataModel.Article;
                order.Articles.Add(newArticle);
            }


            await repo.InsertAsync(order);

            // webAPI client code
            int i = 0;
            await WebApiClient.DoneOrderAsync((int)order.ID, TypeOrder.placeorder);


            // Some info output
            result = string.Format("Purchased. Your order-ID is <{0}>. Total price is {1}.", order.ID, CheckOutSum);
            MessageBox.Show(result);

            // Cleara ut
            Checkout.Clear();

            // Reset Counter
            NumberOfItemsInCheckout = Checkout.Count();

            // Reset price
            CheckOutSum = CheckOutSum * 0;
        }