@RequestMapping(
      value = {"/updateapplication/{id}"},
      method = {RequestMethod.POST})
  public ModelAndView updateapplication(
      @PathVariable Long id,
      @ModelAttribute("application") Application application,
      Model model,
      BindingResult bindingResult,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    Application application1 = mechanicService.getApplicationById(id);
    applicationValidator.validate(application, bindingResult);
    if (bindingResult.hasErrors()) {

      UserPrincipal user = userService.getUserByName(auth.getName());
      Number size1 = directorService.getSizeMechanicOnSto(application1.getSto());
      int size = Integer.parseInt(size1.toString());
      mav.addObject("application", application1);
      mav.addObject("statuss", directorService.getStatus());
      mav.addObject("mechanics", directorService.getMechanicsOnSto(application1.getSto(), 0, size));
      mav.addObject("user", user);
      mav.setViewName("director.updateapplication");
      return mav;
    }

    application1.setMechanic(application.getMechanic());
    application1.setStatus(application.getStatus());
    clientService.addOrUpdateApplication(application1);
    mav.setViewName("redirect:/home");
    return mav;
  }
  @RequestMapping(
      value = {"/updateapplicationdetail/{id}"},
      method = {RequestMethod.POST})
  public ModelAndView updateapplicationdetail(
      @PathVariable Long id,
      @ModelAttribute("applicationdetails") ApplicationDetail applicationDetail,
      BindingResult bindingResult,
      Model model,
      HttpSession session,
      Authentication auth) {
    ModelAndView mav = new ModelAndView();
    applicationDetailValidator.validate(applicationDetail, bindingResult);
    if (bindingResult.hasErrors()) {
      UserPrincipal user = userService.getUserByName(auth.getName());
      mav.addObject("statuss", directorService.getStatus());
      mav.addObject("applicationdetail", directorService.getApplicationDetailById(id));
      mav.addObject("user", user);
      mav.setViewName("director.updateapplicationdetail");
      return mav;
    }

    ApplicationDetail applicationDetail1 =
        directorService.getApplicationDetailById(applicationDetail.getId());
    applicationDetail1.setStatus(applicationDetail.getStatus());
    applicationDetail1.setDateDelivery(applicationDetail.getDateDelivery());
    // applicationDetail.setId(1l);
    directorService.saveApplicationDetail(applicationDetail1);
    mav.setViewName("redirect:/home");
    return mav;
  }
 @PreAuthorize("isFullyAuthenticated()")
 @RequestMapping(value = "/updateapplicationdetail/{id}", method = RequestMethod.GET)
 public ModelAndView updateapplicationdetail(
     @PathVariable Long id, HttpSession session, Authentication auth) {
   ModelAndView mav = new ModelAndView();
   UserPrincipal user = userService.getUserByName(auth.getName());
   mav.addObject("statuss", directorService.getStatus());
   mav.addObject("applicationdetail", directorService.getApplicationDetailById(id));
   mav.addObject("user", user);
   mav.setViewName("director.updateapplicationdetail");
   return mav;
 };
 @PreAuthorize("isFullyAuthenticated()")
 @RequestMapping(value = "/updateapplication/{id}", method = RequestMethod.GET)
 public ModelAndView updateapplication(
     @PathVariable Long id, HttpSession session, Authentication auth) {
   ModelAndView mav = new ModelAndView();
   UserPrincipal user = userService.getUserByName(auth.getName());
   Application application = mechanicService.getApplicationById(id);
   Number size1 = directorService.getSizeMechanicOnSto(application.getSto());
   int size = Integer.parseInt(size1.toString());
   mav.addObject("application", application);
   mav.addObject("statuss", directorService.getStatus());
   mav.addObject("mechanics", directorService.getMechanicsOnSto(application.getSto(), 0, size));
   mav.addObject("user", user);
   mav.setViewName("director.updateapplication");
   return mav;
 };