コード例 #1
0
        // rent your items
        public void Order(object sender, RoutedEventArgs e)
        {
            try // check for valid selected item
            {
                User user = (User)cbUser.SelectedItem;
                if (user != null)                   // check for not null
                {
                    if (OrderItemList.Count() != 0) // check for orderlist not empty
                    {
                        // create rental order object
                        RentalOrder rentalOrder = new RentalOrder();
                        rentalOrder.UserId        = user.Id;
                        rentalOrder.UserFirstName = user.FirstName;
                        rentalOrder.UserName      = user.Name;
                        rentalOrder.UserEmail     = user.Email;
                        rentalOrder.CreatedAt     = DateTime.Now;
                        rentalOrderService.Create(rentalOrder);

                        // get rental order id
                        var rentalOrderId = rentalOrderService.All().Last().Id;

                        // rent all the items form order table
                        foreach (var rentalItem in OrderItemList)
                        {
                            rentalOrderLineService.Rent(rentalOrderId, rentalItem.Id);
                        }
                        this.Close();
                    }
                    else
                    {
                        string mesg = "You did not select a rental item!";
                        MessageBox.Show(mesg);
                    }
                }
                else
                {
                    string mesg = "You did not select a user!";
                    MessageBox.Show(mesg);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                string mesg = "You did not select a user!";
                MessageBox.Show(mesg);
            }
        }
コード例 #2
0
        // fills the order table
        public void FillOrderTable()
        {
            var list = rentalOrderService.All();

            OrderTable.ItemsSource = list;
        }