// 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/delete-event"},
     method = RequestMethod.POST)
 public String deleteEvents(
     ModelMap modelMap,
     @RequestParam String eventId,
     @RequestParam String theReasonForRemoval,
     Principal principal) {
   EventEntity eventEntity = eventService.findById(eventId);
   if (null != eventId && null != eventEntity) {
     List<String> usersMail = eventService.getMailParticipants(eventId);
     String[] userMailArray = new String[usersMail.size()];
     eventEntity.setTheReasonForRemoval(theReasonForRemoval);
     eventEntity.setEventStatus("Проведение мероприятия остановленно");
     eventService.update(eventEntity);
     try {
       mailService.sendEmail(
           MailMessageText.removeEventLetterRegisterOfEventHeader(eventEntity),
           MailMessageText.removeEventLetterRegisterOfEventHeader(eventEntity),
           usersMail.toArray(userMailArray));
     } catch (MessagingException e) {
       modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION);
       return "pages/general/success-template-page";
     }
     modelMap.addAttribute("textPage", ActionMessage.STOPPING_OF_CONDUCT);
     return "pages/general/success-template-page";
   } else {
     modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION);
     return "pages/general/success-template-page";
   }
 }
  @RequestMapping(
      value = "/workspace/trade-union-activists/update-event-images",
      method = RequestMethod.POST,
      produces = "text/plain; charset=utf-8")
  public String getUpdateEventImg(
      @ModelAttribute("uploadForm") FileUploadForm uploadForm,
      ModelMap map,
      @RequestParam String eventId,
      @RequestParam(required = false) String[] idPictures) {

    EventEntity eventEntity = eventService.findById(eventId);

    Set<ImageEntity> imageEntityList = new HashSet<>();

    if (null != idPictures) {
      imageEntityList = eventService.deleteFromEventsImage(eventEntity, idPictures);
    }

    byte fileBytes[];
    FileOutputStream fos = null;
    List<MultipartFile> list = uploadForm.getFiles();
    List<String> filenames = new ArrayList<>();
    if (list != null && list.size() > 0) {
      for (MultipartFile multipartFile : list) {
        final String fileName = multipartFile.getOriginalFilename();
        String webappRoot = servletContext.getRealPath("/");
        final String relativeFolder =
            "/resources" + File.separator + "img" + File.separator + "files" + File.separator;
        String path = webappRoot + relativeFolder + fileName;

        if (checkFormatFileUtils.checkingForImage(fileName)) {
          ImageEntity imageEntity =
              new ImageEntity() {
                {
                  setIdImage(Utils.generateIdentifier());
                  setPathToTheFileSystem(relativeFolder + fileName);
                }
              };
          imageEntityList.add(imageEntity);
        }
        try {
          fos = new FileOutputStream(new File(path));
          fileBytes = multipartFile.getBytes();
          fos.write(fileBytes);
          filenames.add(fileName);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    if (null != imageEntityList) {
      eventEntity.setEventImages(imageEntityList);
    }
    eventService.update(eventEntity);
    map.addAttribute("textPage", ActionMessage.READ_EVENT);
    return "pages/general/success-template-page";
  }
 @RequestMapping(
     value = {"/workspace/general/delete-event"},
     method = RequestMethod.GET)
 public String deleteEventsIndex(ModelMap modelMap, @RequestParam String eventId) {
   EventEntity eventEntity = eventService.findById(eventId);
   if (null != eventId && null != eventEntity) {
     modelMap.addAttribute("eventId", eventId);
     return "pages/trade-union-activists/events/event/event-delete";
   } else {
     modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION);
     return "pages/general/success-template-page";
   }
 }
 @RequestMapping(
     value = {"/workspace/general/details-event"},
     method = RequestMethod.GET)
 public String detailsEvents(
     ModelMap modelMap, @RequestParam String eventId, Principal principal) {
   EventEntity eventEntity = eventService.findById(eventId);
   if (null != eventId && null != eventEntity) {
     modelMap.addAttribute("eventDetails", eventEntity);
     modelMap.addAttribute("listTypeOfEvents", eventTypeService.typeOfEventEntities());
     return "pages/general/event/event-details";
   } else {
     modelMap.addAttribute("textPage", ActionMessage.ERROR_ACTION);
     return "pages/general/success-template-page";
   }
 }
 @RequestMapping(
     value = {"/workspace/general/update-event"},
     method = RequestMethod.POST,
     produces = "application/json; charset=utf-8")
 public @ResponseBody String updateEvents(
     @RequestParam String eventName,
     @RequestParam String typeOfEvent,
     @RequestParam String countParticipants,
     @RequestParam String dateBegin,
     @RequestParam String dateEnd,
     @RequestParam String descriptionEvent,
     @RequestParam String roleUser,
     @RequestParam String eventId,
     Principal principal,
     ModelMap modelMap) {
   EventEntity eventEntity = eventService.findById(eventId);
   if (null != eventId && null != eventEntity) {
     if (eventService.checkChangeRoleUsersOnEvent(roleUser, eventId)) {
       if (eventService.changeCountParticipantsUser(countParticipants, eventId)) {
         TypeOfEventEntity typeOfEventEntity = eventTypeService.findById(typeOfEvent);
         eventEntity.setRoleParticipants("[" + roleUser + "]");
         eventEntity.setEventDescription(descriptionEvent);
         eventEntity.setEventName(eventName);
         eventEntity.setCountParticipants(new Integer(countParticipants));
         eventEntity.setDateAndTimeBegin(Utils.convertStringToSqlFormatDate(dateBegin));
         eventEntity.setDateAndTimeEnd(Utils.convertStringToSqlFormatDate(dateEnd));
         eventEntity.setIdTypeOfEvent(typeOfEventEntity.getIdTypeOfEvent());
         eventEntity.setEventStatus(eventService.checkStatusEvent(dateBegin, dateEnd));
         eventService.update(eventEntity);
         return String.valueOf(HttpStatus.OK);
       } else {
         return String.valueOf(ActionMessage.ERROR_CHANGE_COUNT_PARTICIPANTS);
       }
     } else {
       return String.valueOf(ActionMessage.ERROR_CHANGE_EVENT_USER_ROLE);
     }
   } else {
     return ActionMessage.ERROR_ACTION;
   }
 }
 @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";
 }