Exemple #1
0
        public RestaurantTransaction addRestaurantTransaction(RestaurantTransaction transaction)
        {
            Connection con = Connection.getConnection();

            con.db.RestaurantTransaction.Add(transaction);
            con.db.SaveChanges();

            return(transaction);
        }
        public RestaurantTransaction createNewRestaurantTransaction(int seatID)
        {
            RestaurantTransactionMediator mediator = new RestaurantTransactionMediator();

            RestaurantTransaction transaction = new RestaurantTransaction();

            transaction.transactionID = mediator.getLastID() + 1;
            transaction.employeeID    = Session.getSession().employee.employeeID;
            transaction.seatID        = seatID;
            transaction.purchaseDate  = DateTime.Now;

            return(transaction);
        }
        private void checkOutButton_Click(object sender, RoutedEventArgs e)
        {
            string paymentStr = paymentTxt.Text.Trim();
            int    payment;

            bool success = int.TryParse(paymentStr, out payment);

            if (!success)
            {
                errorLbl.Text = "Payment must be a number!";
            }
            else if (totalPrice == 0 || tax == 0)
            {
                errorLbl.Text = "Please input Seat ID!";
            }
            else
            {
                int change = (totalPrice + tax) - payment;
                if (change > 0)
                {
                    errorLbl.Text = "Payment is not enough!";
                }
                else if (change <= 0)
                {
                    SeatMediator  mediator      = new SeatMediator();
                    OrderMediator omediator     = new OrderMediator();
                    Order         customerOrder = omediator.getOrderBySeat(seatID);

                    changeTxt.Text = "Change = \t\tRp. " + Math.Abs(change).ToString();

                    RestaurantTransactionMediator tmediator   = new RestaurantTransactionMediator();
                    RestaurantTransactionFactory  tfactory    = new RestaurantTransactionFactory();
                    RestaurantTransaction         transaction = tmediator.addRestaurantTransaction(tfactory.createNewRestaurantTransaction(seatID));
                    if (tmediator.addDetailRestaurantTransaction(transaction.transactionID, customerOrder.orderID) == null)
                    {
                        MessageBox.Show("Checkout failed!");
                    }
                    else
                    {
                        MessageBox.Show("Checkout success!");
                    }

                    //update seat dan ordernya
                    Seat customerSeat = mediator.getSeat(seatID);
                    customerSeat.status  = "Available";
                    customerSeat         = mediator.updateSeat(seatID, customerSeat);
                    customerOrder.status = "Finished";
                    customerOrder        = omediator.updateOrder(customerOrder.orderID, customerOrder);
                }
            }
        }
Exemple #4
0
        public int getLastID()
        {
            Connection con = Connection.getConnection();

            RestaurantTransaction transaction = (from t in con.db.RestaurantTransaction
                                                 orderby t.transactionID descending
                                                 select t).FirstOrDefault();

            if (transaction == null)
            {
                return(0);
            }
            return(transaction.transactionID);
        }
        public RestaurantTransaction addRestaurantTransaction(RestaurantTransaction transaction)
        {
            RestaurantTransactionRepository repository = new RestaurantTransactionRepository();

            return(repository.addRestaurantTransaction(transaction));
        }