@RequestMapping( value = {"/addmechanic"}, method = {RequestMethod.POST}) public ModelAndView addmechanic( @ModelAttribute("mechanic") Mechanic mechanic, BindingResult bindingResult, Model model, HttpSession session, Authentication auth) { ModelAndView mav = new ModelAndView(); mechanicValidator.validate(mechanic, bindingResult); if (bindingResult.hasErrors()) { UserPrincipal user = userService.getUserByName(auth.getName()); mav.addObject("user", user); mav.addObject("stos", directorService.getSto()); mav.setViewName("director.addmechanic"); return mav; } mechanic.setLogin(mechanic.getName()); mechanic.setRating((float) 0); mechanic.setRole(UserRole.MECHANIC); directorService.saveOrUpdateMechanic(mechanic); mav.setViewName("redirect:/home"); return mav; }
@RequestMapping( value = {"/addsalary/{id}"}, method = {RequestMethod.GET}) public String addsalaryByMechanic(@PathVariable Long id, Model model, HttpSession session) { Mechanic mechanic = directorService.getMechanicById(id); Salary salary = new Salary(); salary.setMechanic(mechanic); salary.setSumma(new Float(mechanic.getSalary())); salary.setDate(new Date()); directorService.addSalary(salary); return "redirect:/home"; }