public void bookRoom() { bookRoomResult = ""; if (customerBean.getCurCust() == null) { // Customer tmp = customerBean.getCurCust(); bookRoomResult = "requiredlogin"; return; } try { OrderRoom order = new OrderRoom(); // OrderDetail orderDetail = new OrderDetail(); order.setOrderId(1); order.setCustID(curAccom.getCustId()); order.setTotalPrice(new BigDecimal(curAccom.getPrice(), MathContext.DECIMAL64)); order.setOrderDate(new Date()); order.setStatus("Đã đặt phòng"); order1Facade.create(order); bookRoomResult = "success"; } catch (Exception ex) { printStackTrace(); bookRoomResult = "false"; } }
public void createComment() { try { Comments com = new Comments(); Date date = new Date(); com.setComId(1); com.setAccomId(curAccom); com.setCustId(curAccom.getCustId()); com.setContent(commentMessage); com.setComDate(date); commentsFacade.create(com); } catch (Exception ex) { printStackTrace(); } }
public void roomRating() { // FacesContext context = FacesContext.getCurrentInstance(); // context.addMessage(null, new FacesMessage("Successful", "Your message: ")); // context.addMessage(null, new FacesMessage("Second Message", "Additional Message // Detail")); try { Rating rate = new Rating(); rate.setRateId(1); rate.setCustId(curAccom.getCustId()); rate.setAccomId(curAccom); rate.setScore(Integer.parseInt(roomRatingSelected)); ratingFacade.create(rate); } catch (Exception ex) { printStackTrace(); } }
public String createRoom() { try { // log.info("call upload..."); // log.log(Level.INFO, "content-type:{0}", file.getContentType()); // log.log(Level.INFO, "filename:{0}", file.getName()); // log.log(Level.INFO, "submitted filename:{0}", file.getSubmittedFileName()); Date date = new Date(); DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); roomImageFileNames = new ArrayList<>(); List<Part> files = new ArrayList<Part>(); files.add(thumbnail); files.add(file1); files.add(file2); files.add(file3); // Uploading room image for (Part itemFile : files) { if (itemFile == null) { continue; } InputStream inputStream = itemFile.getInputStream(); String fileName = dateFormat.format(date) + getFilename(itemFile); roomImageFileNames.add(fileName); File file = new File("C:/room4u/images/" + fileName); FileOutputStream outputStream = new FileOutputStream(file); if (!file.exists()) { file.createNewFile(); } byte[] buffer = new byte[6096]; int bytesRead = 0; while (true) { bytesRead = inputStream.read(buffer); if (bytesRead > 0) { outputStream.write(buffer, 0, bytesRead); } else { break; } } outputStream.close(); inputStream.close(); } // FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Room is // created!")); room.setAccomId(1); Customer cust = customerFacade.find(1); room.setCustId(cust); room.setAddress(houseNumber + " " + street + " " + ward + " " + district + " " + city); room.setCreatedDate(date); room.setCreatedBy("Can"); // Store Image File name as json string. RoomImage roomImage = new RoomImage(); roomImage.setThumbnail(roomImageFileNames.get(0)); roomImage.setSlider1(roomImageFileNames.get(1)); roomImage.setSlider2(roomImageFileNames.get(2)); roomImage.setSlider3(roomImageFileNames.get(3)); Gson gson = new Gson(); String jsonImage = gson.toJson(roomImage); room.setImages(jsonImage); accommodationFacade.create(room); // RequestContext.getCurrentInstance().execute("alert('peek-a-boo');"); } catch (Exception ex) { printStackTrace(); } return "index"; }
public String displayRoomDetail(int id) { try { Accommodation accom = accommodationFacade.find(id); if (accom != null) { curAccom = new Accommodation(); curAccom.setAccomName(accom.getAccomName()); curAccom.setDescription(accom.getDescription()); curAccom.setPrice(accom.getPrice()); curAccom.setAccomId(id); curAccom.setNoOfBed(accom.getNoOfBed()); curAccom.setNoOfPersons(accom.getNoOfPersons()); curAccom.setNoOfToilet(accom.getNoOfToilet()); curAccom.setCustId(customerFacade.find(1)); List<Comments> commentsCount = commentsFacade.findCommentsByAccomId( id); // != null ? commentsFacade.findCommentsByAccomId(id).size() : 0; Gson gson = new Gson(); RoomImage roomImage = gson.fromJson(accom.getImages(), RoomImage.class); // curAccom.setImages(accom.getImages()); slider1 = roomImage.getSlider1(); slider2 = roomImage.getSlider2(); slider3 = roomImage.getSlider3(); List<Rating> ratings = ratingFacade.findByAccRoomId(id); int sumRateScore = 0; for (Rating rate : ratings) { sumRateScore += rate.getScore(); } displayRate = ratings.size() > 0 ? sumRateScore / ratings.size() : 0; } } catch (Exception ex) { printStackTrace(); } return "roomdetail"; }
public void displayAccomUpdate(Accommodation acc) { // curAccomUpdate = null; curAccomUpdate = new Accommodation(); curAccomUpdate.setAccomName(acc.getAccomName()); curAccomUpdate.setDescription(acc.getDescription()); curAccomUpdate.setAddress(acc.getAddress()); curAccomUpdate.setNoOfBed(acc.getNoOfBed()); curAccomUpdate.setNoOfPersons(acc.getNoOfPersons()); curAccomUpdate.setNoOfToilet(acc.getNoOfToilet()); curAccomUpdate.setPrice(acc.getPrice()); Gson gson = new Gson(); String jsonRoom = gson.toJson(curAccomUpdate); UpdateRoomResult = jsonRoom; }