/** * * Adminsitration User edit page * * @param userId * @param request * @param response * @param model * @return */ @RequestMapping(value = "/administration/users/edit/{userId}", method = RequestMethod.GET) public ModelAndView EditUser( @PathVariable Integer userId, @ModelAttribute("viewModel") AdministrationUserEditViewModel viewModel, Model model) { ModelAndView result = new ModelAndView("administration_user_edit"); viewModel.setUserId(userId); User user = _accountService.getUserByID(userId); Userhandle userHandle = _accountService.GetUsrHandleByID(userId); if (userHandle != null) { viewModel.setFirstName(userHandle.getFirstName()); viewModel.setLastName(userHandle.getLastName()); viewModel.setHeight(String.valueOf(userHandle.getHeightIn())); viewModel.setGender(userHandle.getGenderName()); Calendar dob = Calendar.getInstance(); dob.setTime(userHandle.getDob()); Calendar today = Calendar.getInstance(); int age = today.get(Calendar.YEAR) - dob.get(Calendar.YEAR); viewModel.setAge(age); viewModel.setHandedness("Right Handed"); } viewModel.setEmail(user.getEmail()); viewModel.setPassword(user.getUserpassword()); viewModel.setAdmin(user.getIsAdmin()); // if(hand == 1) // viewModel.setHandedness("Right"); // else viewModel.setHandedness("Left"); model.addAttribute("model", viewModel); return result; }
/** * Post request to update user. Update email, first, last, password and handId. Does not update * birthday or gender. Gender does not exist as a field in the DB and for sake of time Birthday * was not completed. * * @param userId * @param request * @param response * @return */ @RequestMapping(value = "/adminsitration/users/update-user", method = RequestMethod.POST) public ModelAndView UpdateUser( @ModelAttribute("viewModel") AdministrationUserEditViewModel viewModel, Model model, RedirectAttributes redirectAttributes) { ModelAndView result = new ModelAndView("redirect:/administration/users"); int userID = viewModel.getUserId(); if (viewModel.getEmail() != null) _accountService.updateUserEmail(userID, viewModel.getEmail()); if (viewModel.getFirstName() != null) _accountService.updateUserHandleFirstName(userID, viewModel.getFirstName()); if (viewModel.getLastName() != null) _accountService.updateUserHandleLastName(userID, viewModel.getLastName()); if (viewModel.getPassword() != null) _accountService.updateUserPassword(userID, viewModel.getPassword()); if (viewModel.getHandedness() != null) _accountService.updateUserHandId(userID, viewModel.getHandedness()); model.addAttribute("model", viewModel); return result; }