/// <summary>
        /// Locations don't want to allow orders to occur if their stocks don't have enough product
        /// The purpose of this function is to ensure that the stocks have enough books to place an order.
        /// </summary>
        /// <param name="newOrder"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public bool AttemptOrderAtLocation(Order newOrder, out string message)
        {
            string response  = "";
            int    attempted = 0;

            // We check each orderline that exists to get the isbns that were in the order
            foreach (OrderLine ol in newOrder.Purchase)
            {
                // Check each one if the book is even in the library and if there is enough
                if (CheckStockForOrderAttempt(Book.Library.Find(b => b.ISBN.Contains(ol.BookISBN)), ol.Quantity, out response))
                {
                    response = "\n" + response;
                    attempted++;
                }
            }
            message = response;

            // Just a double check that the amount books checked equal to the books that were attempted to place
            if (newOrder.Purchase.Count == attempted)
            {
                foreach (OrderLine ol in newOrder.Purchase)
                {
                    // Since we made it this far we can assume that the stocks exist for the books we want to purchase so we adjust the stocks
                    Inventory.Find(b => b.Book.ISBN == ol.BookISBN).AdjustStock(ol.Quantity);
                }

                // We also add this order to this locations order history
                OrderHistory.Add(newOrder);
                return(true);
            }

            return(false);
        }
示例#2
0
        public async void LoadOrderHistoryAsync(int passengerId)
        {
            HttpClient client = new HttpClient();
            var        json   = await client.GetStringAsync(new Uri($"http://localhost:60177/api/Order/passengers/{passengerId}/orderHistory"));

            var orders = JsonConvert.DeserializeObject <List <Order> >(json);

            foreach (Order order in orders)
            {
                OrderViewModel orderViewModel = new OrderViewModel(order);
                OrderHistory.Add(orderViewModel);
            }
        }
示例#3
0
 public void SetOrderHistory(Order order)
 {
     OrderHistory.Add(order);
 }