Package eja.controllers

Source Code of eja.controllers.BookingController

package eja.controllers;

import eja.ejb.dao.BookingDao;
import eja.ejb.dao.CustomerDao;
import eja.ejb.dao.HotelDao;
import eja.ejb.entities.Booking;
import eja.ejb.entities.Customer;
import eja.ejb.entities.Hotel;
import java.util.Collection;
import java.util.Date;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
*
* @author fero
*/
@ManagedBean
@RequestScoped
public class BookingController {


    @EJB
    private BookingDao _bookingDao;

    @EJB
    private CustomerDao _customerDao;

    @EJB
    private HotelDao _hotelDao;

    @ManagedProperty("#{param['id']}")
    private int id;
    private Customer customer;
    private Hotel hotel;
    private String bookingNo;
    private Date dateFrom;
    private Date dateTo;
    private int price;
    private String persons;
    private boolean canceled;
    private boolean closed;
    private boolean confirmed;



    private Booking _booking;

    public BookingController() {
    }

    public Collection<Booking> getAllBookings() {
        return this._bookingDao.getAllBookings();
    }

    public Collection<Customer> getAllCustomers() {
        return this._customerDao.getAllCustomers();
    }

    public Collection<Hotel> getAllHotels() {
        return this._hotelDao.getAllHotels();
    }

    public String edit() {
        this._booking = (this.id != 0) ? this._bookingDao.getBookingById(this.id) : new Booking();
        this._booking.setHotel(this.hotel);
        this._booking.setCustomer(this.customer);
        this._booking.setBookingNo(this.bookingNo);
        this._booking.setDateFrom(this.dateFrom);
        this._booking.setDateTo(this.dateTo);
        this._booking.setPrice(this.price);
        this._booking.setPersons(this.persons);
        this._booking.setCanceled(this.canceled);
        this._booking.setClosed(this.closed);
        this._booking.setConfirmed(this.confirmed);

        this._bookingDao.saveBooking(this._booking);
        return "booking-details";
    }


    public void load() {
        this._booking = this._bookingDao.getBookingById(this.id);

        this.hotel = this._booking.getHotel();
        this.customer = this._booking.getCustomer();
        this.bookingNo = this._booking.getBookingNo();
        this.dateFrom = this._booking.getDateFrom();
        this.dateTo = this._booking.getDateTo();
        this.price = this._booking.getPrice();
        this.persons = this._booking.getPersons();
        this.canceled = this._booking.isCanceled();
        this.closed = this._booking.isClosed();
        this.confirmed = this._booking.isConfirmed();
    }

    // Getters & Setters
    public Booking getBooking() {
        return this._booking;
    }

    public void setBooking(Booking _booking) {
        this._booking = _booking;
    }

    public String getBookingNo() {
        return bookingNo;
    }

    public void setBookingNo(String bookingNo) {
        this.bookingNo = bookingNo;
    }

    public boolean isCanceled() {
        return canceled;
    }

    public void setCanceled(boolean canceled) {
        this.canceled = canceled;
    }

    public boolean isClosed() {
        return closed;
    }

    public void setClosed(boolean closed) {
        this.closed = closed;
    }

    public boolean isConfirmed() {
        return confirmed;
    }

    public void setConfirmed(boolean confirmed) {
        this.confirmed = confirmed;
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    public Date getDateFrom() {
        return dateFrom;
    }

    public void setDateFrom(Date dateFrom) {
        this.dateFrom = dateFrom;
    }

    public Date getDateTo() {
        return dateTo;
    }

    public void setDateTo(Date dateTo) {
        this.dateTo = dateTo;
    }

    public Hotel getHotel() {
        return hotel;
    }

    public void setHotel(Hotel hotel) {
        this.hotel = hotel;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        if (id == 0)
            return;

        this.id = id;
        this.load();
    }

    public String getPersons() {
        return persons;
    }

    public void setPersons(String persons) {
        this.persons = persons;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

}
TOP

Related Classes of eja.controllers.BookingController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.