Esempio n. 1
0
        /// <summary>
        /// This method cancels an order. Once the order is cancelled it will replace the goods back to the basket that were held against that order.
        ///
        /// Test Case:  Req-7
        /// </summary>
        /// <param name="order_id">The order id of the cancelled order</param>
        /// <returns>Message indicating order has been cancelled</returns>
        public string CancelOrder(int order_id)
        {
            using (SqlConnection conn = new SqlConnection(defaultConnection))
            {
                string query = "update cust_order set cancelled_ts = getdate() " +
                               "where order_id = @order_id";

                SqlCommand myCmd = new SqlCommand(query, conn);

                myCmd.Parameters.AddWithValue("@order_id", order_id);

                conn.Open();

                myCmd.ExecuteNonQuery();

                // get the order items
                List <CustOrderItem> coiList = new List <CustOrderItem>();
                BasketDAL            basket  = new BasketDAL();
                int basket_id = GetOrderBasketId(order_id);
                coiList = GetOrderItems(order_id);

                // add stock back to basket (if order was already assigned to a basket. basket_id = 0 means not assigned yet)
                if (basket_id > 0)
                {
                    foreach (CustOrderItem coi in coiList)
                    {
                        basket.ReturnBasketItem(basket_id, coi.product_id, coi.qty);
                    }
                }

                return("Your order has been cancelled");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// This method determines which basket to give the order to.
        ///
        /// Test Case:  Req-8, Req-9, Req-11
        /// </summary>
        /// <param name="delivery_location">Object containing the delivery location</param>
        /// <param name="order_id">The related order id</param>
        /// <returns>KeyValuePair: basket_id, distance to customer</returns>
        private KeyValuePair <int, int> FindAvailableBasket(LocationCoordinates delivery_location, int order_id)
        {
            int basket_id    = 0;
            int min_distance = 9999;
            // KeyValuePair - Key = bsaket_id; Value = location_cell_id
            var basketList  = new List <KeyValuePair <int, int> >();
            var basket      = new BasketDAL();
            var locationDAL = new LocationDAL();

            basketList = basket.BasketHasStock(order_id);

            // get basket that is closest to delivery location
            foreach (KeyValuePair <int, int> kvp in basketList)
            {
                var basket_location = locationDAL.GetLocationCell(kvp.Value);
                int basket_distance = locationDAL.CalculateDistanceToCustomer(delivery_location.x, delivery_location.y, basket_location.x_coord, basket_location.y_coord);
                if (basket_distance < min_distance)
                {
                    min_distance = basket_distance;
                    basket_id    = kvp.Key;
                }
            }
            return(new KeyValuePair <int, int>(basket_id, min_distance));
        }