package controller; import java.io.Serializable; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; import javax.validation.Validation; import model.Comment; import model.Offer; import model.Order1; import model.UserAccount; import service.impl.CommentServiceImpl; import service.impl.OfferServiceImpl; import service.impl.UserAccountServiceImpl; @Named("commentController") @SessionScoped public class CommentController implements Serializable { private String commentText; private List commentList; private int selectedCommentIndex; private int commentId; private String offerCommentText; private Offer selectedOffer = new Offer(); private Comment selectedComment = new Comment(); private int oldValue; private int currentValue; private Offer offerId; @Inject private CommentServiceImpl commentService; @Inject private OfferServiceImpl offerService; @Inject private UserAccountServiceImpl userAccountService; @Inject private OfferController offerController; public String getCommentText() { return commentText; } public void setCommentText(String commentText) { this.commentText = commentText; } public List getCommentList() { return commentList; } public void setCommentList(List commentList) { this.commentList = commentList; } public int getSelectedCommentIndex() { return selectedCommentIndex; } public void setSelectedCommentIndex(int selectedCommentIndex) { this.selectedCommentIndex = selectedCommentIndex; } public Integer getCommentId() { return commentId; } public void setCommentId(Integer commentId) { this.commentId = commentId; } public String getOfferCommentText() { return offerCommentText; } public void setOfferCommentText(String offerCommentText) { this.offerCommentText = offerCommentText; } public Offer getSelectedOffer() { return selectedOffer; } public void setSelectedOffer(Offer selectedOffer) { this.selectedOffer = selectedOffer; } public OfferServiceImpl getOfferService() { return offerService; } public void setOfferService(OfferServiceImpl offerService) { this.offerService = offerService; } public int getOldValue() { return oldValue; } public void setOldValue(int oldValue) { this.oldValue = oldValue; } public int getCurrentValue() { return currentValue; } public void setCurrentValue(int currentValue) { this.currentValue = currentValue; } public CommentServiceImpl getCommentService() { return commentService; } public void setCommentService(CommentServiceImpl commentService) { this.commentService = commentService; } public UserAccountServiceImpl getUserAccountService() { return userAccountService; } public void setUserAccountService(UserAccountServiceImpl userAccountService) { this.userAccountService = userAccountService; } public Offer getOfferId() { return offerId; } public void setOfferId(Offer offerId) { this.offerId = offerId; } // sprwdzanie czy użytkonik ma jakąś ofertę // public void initCommentData() { // UserAccount loggedUser = userAccountService.getLoggedUser(); // if (loggedUser != null) { // if (!FacesContext.getCurrentInstance().isPostback()) { // offerToAdd = commentService.get(); // } // } // } public void addComment() { Comment commentToBeAdded = selectedComment; Offer offerId = offerController.getSelectedOffer(); UserAccount user = userAccountService.getLoggedUser(); commentToBeAdded.setCommentText(commentText); commentToBeAdded.setCommentCreatingTime(new Date()); commentToBeAdded.setCommentId(commentId); commentToBeAdded.setUserId(user); commentToBeAdded.setOfferId(offerId); commentService.create(commentToBeAdded); } }