예제 #1
0
  @RequestMapping(value = "/shift/{shiftId}/edit", method = RequestMethod.POST)
  public ModelAndView editShift(
      @PathVariable("shiftId") final Integer shiftId,
      @Valid @ModelAttribute("shift") Shift shift,
      BindingResult result) {
    ModelAndView mav = new ModelAndView();

    if (result.hasErrors()) {
      return new ModelAndView("shift/create", "shift", shift);
    }

    Event event = eventService.get(shift.getEvent().getId());

    // Set Dates to today
    shift.setStartTime(convertDateToToday(shift.getStartTime(), event.getDate()));
    shift.setEndTime(convertDateToToday(shift.getEndTime(), event.getDate()));

    try {
      shiftService.edit(shift);
    } catch (NotValidException e) {
      LOGGER.warn(e);
      result.addAllErrors(e.getErrors());
      return new ModelAndView("shift/create", "shift", shift);
    }

    return new ModelAndView("redirect:/event/" + shift.getEvent().getId() + "/edit");
  }
예제 #2
0
  @RequestMapping(value = "/shift/{eventId}/create", method = RequestMethod.GET)
  public ModelAndView createShift(@PathVariable("eventId") Integer eventId) {
    ModelAndView mav = new ModelAndView("shift/create");

    Shift shift = new Shift();
    shift.setEvent(eventService.get(eventId));

    mav.addObject("shift", shift);

    return mav;
  }