@RequestMapping(value = "/list", method = RequestMethod.GET) public String list(Model model) { Collection<OrderDTO> orders = orderFacade.getAllOrders(); List<CustomerDTO> customers = new ArrayList<CustomerDTO>(); for (OrderDTO order : orders) { customers.add(order.getCustomer()); } if (UserLogged.usernameLogged.equals("user")) { int i = 0; Iterator<OrderDTO> orderIterator = orders.iterator(); for (Iterator<CustomerDTO> iterator = customers.iterator(); iterator.hasNext(); i++) { if (orderIterator.hasNext()) { OrderDTO order = orderIterator.next(); } CustomerDTO customer = iterator.next(); if (!customer.getEmail().equals("*****@*****.**")) { orderIterator.remove(); iterator.remove(); } } } model.addAttribute("orders", orders); model.addAttribute("customers", customers); return "order/list"; }
@RequestMapping(value = "/submit", method = RequestMethod.POST) public String index( @Valid @ModelAttribute("orderForm") OrderFormDTO orderForm, Model m, BindingResult result, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) { List<Long> serviceIds = orderForm.getServiceIds(); List<Long> tireIds = orderForm.getTireIds(); OrderDTO order = new OrderDTO(); for (Long tireId : tireIds) { OrderItemDTO tireItem = new OrderItemDTO(); tireItem.setItem(tireFacade.getTireById(tireId)); order.addOrderItem(tireItem); } for (Long serviceId : serviceIds) { OrderItemDTO serviceItem = new OrderItemDTO(); serviceItem.setItem(serviceFacade.findServiceById(serviceId)); order.addOrderItem(serviceItem); } String email = orderForm.getEmail(); if (email != null) { CustomerDTO customer = new CustomerDTO(); customer.setEmail(email); customerFacade.createCustomer(customer); } redirectAttributes.addFlashAttribute("alert_success", "Order was successfully submitted"); return "redirect:" + uriBuilder.path("/").toUriString(); }
@RequestMapping(value = "/list", method = RequestMethod.GET) public String listOrders(Model m, HttpServletRequest request) { HttpSession session = request.getSession(true); CustomerDTO user = (CustomerDTO) session.getAttribute("auth"); if (user.getIsAdmin()) { m.addAttribute("pendingOrders", orderFacade.getPendingOrders()); m.addAttribute("previousOrders", orderFacade.getPreviousOrders()); } else { m.addAttribute("pendingOrders", orderFacade.getOrdersByCustomer(user.getId())); } return "order/list"; }