/** * * 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; }
/** Lists all of the current users in the system */ @RequestMapping(value = "/administration/users", method = RequestMethod.GET) public ModelAndView ListUsers( @ModelAttribute("viewModel") AdministrationUsersViewModel viewModel, Model model) { ModelAndView result = new ModelAndView("administration_users"); // Bad name for AdmistrationUserListViewModel.... // creates a List of AdmiistrationUserListViewModel objects with custom user fields. List<AdministrationUserListViewModel> usersList = new ArrayList<AdministrationUserListViewModel>(); // grabs all users. List<User> allUsers = _accountService.GetAllUsers(); for (User u : allUsers) { AdministrationUserListViewModel alvm = new AdministrationUserListViewModel(); alvm.setEmail(u.getEmail()); alvm.setIsAdmin(u.getIsAdmin()); alvm.setLastLogin(new Date()); alvm.setName(""); alvm.setUserId(u.getUserId()); usersList.add(alvm); } /*for(User U : allUsers){ AdministrationUserListViewModel temp = new AdministrationUserListViewModel(); Userhandle handle = _accountService.GetUsrHandleByID(U.getUserId()); temp.setEmail(U.getEmail()); temp.setIsAdmin(U.getIsAdmin()); temp.setUserId(U.getUserId()); //SET THE USER's LAST LOGINDATE temp.setLastLogin(new Date()); //might have to edit this out... String firstName, lastName; if(handle.getFirstName() == null){firstName = " ";} else firstName = handle.getFirstName(); if(handle.getLastName() == null){lastName = " ";} else lastName = handle.getLastName(); temp.setName(firstName + " " + lastName); usersList.add(temp); }*/ // pushing all this shit into a userList... // view viewModel.setUserList(usersList); viewModel.setLastAccess(new Date()); model.addAttribute("model", viewModel); return result; }