Esempio n. 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        Booking book = new Booking();

        book.AddBooking(txtFullName.Text, txtCellNumber.Text, txtAddress.Text, txtDate.Text, txtTime.Text, txtMessage.Text);
        lblStatus.Text = book.status;
    }
Esempio n. 2
0
        public ActionResult AddRecord(BorrowViewModel borrowViewModel)
        {
            // Check if borrower has books in his/her possession.
            var borrowersId = borrowViewModel.Borrow.BorrowerId;
            var isbn        = borrowViewModel.Borrow.Isbn;
            var checkBook   = _context.Borrows
                              .SingleOrDefault(b => b.IsReturned == false && b.BorrowerId == borrowersId && b.Isbn == isbn);

            if (checkBook != null)
            {
                var model = new BorrowViewModel((byte)borrowViewModel.MyBooks.Length)
                {
                    BorrowTypes = _context.BorrowTypes.ToList()
                };

                var message =
                    $@"Borrower has {isbn} book in his/her possession already.";
                ModelState.AddModelError(string.Empty, message);
                return(View("AddRecord", model));
            }

            var validator = _context.Borrows
                            .Where(b => b.BorrowerId == borrowViewModel.Borrow.BorrowerId && b.IsReturned == false);
            var settings = _context.Settings.Single(s => s.Id == 1);

            if (validator.Count() >= settings.MaximumNumberOfBooksPerBorrow)
            {
                var model = new BorrowViewModel((byte)borrowViewModel.MyBooks.Length)
                {
                    BorrowTypes = _context.BorrowTypes.ToList()
                };

                var message =
                    string.Format(
                        @"Maximum number of books exceeded, the borrower has {0} books in his/her possession already.",
                        validator.Count());
                ModelState.AddModelError(string.Empty, message);
                return(View("AddRecord", model));
            }


            Booking.AddBooking(borrowViewModel, _context);

            var processBorrowers = new ProcessLendingViewModel(_context);

            ViewBag.Borrowers = _context.Borrows.Where(b => b.IsReturned == false).ToList().Count();

            return(View("Index", processBorrowers.GetLendingDetails()));
        }
Esempio n. 3
0
        // Book Ticket for users
        private void bookButton_Click(object sender, EventArgs e)
        {
            if (null != movieListBox.SelectedItem && !movieListBox.SelectedItem.Equals("")) // checking for null
            {
                try
                {
                    // passing the values from form fields to variables
                    int      bid       = int.Parse(bookingIdTextBox.Text);
                    string   name      = customerNameTextBox.Text;
                    int      seats     = int.Parse(noOfSeatsTextBox.Text);
                    string   phNo      = phoneNumberTextBox.Text;
                    Movie    selMovie  = movieList[movieListBox.SelectedIndex];
                    string   moviename = selMovie.MovieName;
                    DateTime dat       = selMovie.Date;
                    string   stime     = selMovie.ShowTime;
                    Double   unitprice = selMovie.Price;

                    abook = new Booking(bid, moviename, name, phNo, seats, dat, stime, unitprice); //

                    int r = abook.AddBooking(selMovie);                                            // adds the movie to the method AddBooking in Booking Class

                    if (r == -1)                                                                   // checks if there is any bookings added
                    {
                        throw new Exception("Error while adding customer");                        // throws Exception while adding customers
                    }
                    else
                    {
                        // Display the data in MessageBox

                        MessageBox.Show("\tBook Id:" + abook.BookingId + " \n\tMovieName:" + abook.MovieName
                                        + " \n\tCustomer:" + abook.CustName
                                        + " \n\tDate:" + abook.Date
                                        + "  ShowTime:" + abook.ShowTime
                                        + " \n\tAmount Due:" + abook.Price.ToString("c"), "Ticket Booked");
                    }
                }
                catch (Exception ey) { MessageBox.Show(ey.Message); }  // Catching Exceptions
            }
            else
            {
                MessageBox.Show("Select A Movie to Book Tickets", "Movie Not selected");
            }
        }