// delete a paymentCard @RequestMapping(value = "{id}", method = RequestMethod.DELETE) public String delete(@PathVariable Long id, Model model) { paymentCardService.deletePaymentCardById(id); String message = "Succesfully deleted Payment Card."; FlashMap.setSuccessMessage(message); return "redirect:../cards/"; }
// update a paymentCard @RequestMapping(method = RequestMethod.POST) public String update(@Valid PaymentCard paymentCard, BindingResult bindingResult, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/edit"; } paymentCardService.updatePaymentCard(paymentCard); String message = "Succesfully updated Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); }
// add a paymentCard @RequestMapping(method = RequestMethod.PUT) public String add( @Valid PaymentCard paymentCard, BindingResult bindingResult, Principal currentUser, Model model) { if (bindingResult.hasErrors()) { List<String> types = paymentCardService.getTypes(); model.addAttribute("typeList", types); return "cards/add"; } if (currentUser != null) { paymentCardService.addPaymentCard(paymentCard, currentUser.getName()); String message = "Succesfully added Payment Card " + paymentCard.getNumber() + "."; FlashMap.setSuccessMessage(message); return "redirect:/cards/" + paymentCard.getId(); } else { // TODO: return error return "redirect:/cards/add"; } }