// user func @RequestMapping( value = {"/workspace/general/to-participate-in-the-event"}, method = RequestMethod.GET) public String toParticipateInTheEvent( ModelMap modelMap, @RequestParam String eventId, Principal principal) { EventEntity eventEntity = eventService.findById(eventId); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<EventEntity> userEvents = userEntity.getUserEvents(); if (eventEntity.getTheCurrentNumberOfParticipants() + 1 > eventEntity.getCountParticipants()) { modelMap.addAttribute("textPage", ActionMessage.THE_EXCESS_NUMBER_OF_PARTICIPANTS); return "pages/general/success-template-page"; } else { if (null != userEvents) { userEvents.add(eventEntity); } else { userEvents = new HashSet<EventEntity>(); userEvents.add(eventEntity); } userEntity.setUserEvents(userEvents); userService.update(userEntity); try { mailService.sendEmail( MailMessageText.helloLetterRegisterOfEventHeader(eventEntity), MailMessageText.helloLetterRegisterOfEventBody(eventEntity), new String[] {userEntity.getEmail()}); } catch (MessagingException e) { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); } modelMap.addAttribute("textPage", ActionMessage.SUCCESS_EVENT_USER_REGISTRATION); return "pages/general/success-template-page"; } }
@RequestMapping( value = {"/workspace/general/refuse-to-participate-in-the-event"}, method = RequestMethod.GET) public String refuseToParticipateInTheEvent( ModelMap modelMap, @RequestParam String eventId, Principal principal) { EventEntity eventEntity = eventService.findById(eventId); UserEntity userEntity = userService.findByUsername(principal.getName()); Set<EventEntity> userEvents = userEntity.getUserEvents(); userEvents.remove(eventEntity); userEntity.setUserEvents(userEvents); userService.update(userEntity); try { mailService.sendEmail( MailMessageText.cancelLetterRegisterOfEventHeader(eventEntity), MailMessageText.cancelLetterRegisterOfEventBody(eventEntity), new String[] {userEntity.getEmail()}); } catch (MessagingException e) { modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION); } modelMap.addAttribute("textPage", ActionMessage.CANCEL_EVENT_USER_REGISTRATION); return "pages/general/success-template-page"; }