/**
  * Request method to delete user
  *
  * @param id of user
  * @return view
  */
 @RequestMapping(value = "/delete/user", method = RequestMethod.GET)
 public ModelAndView deleteUser(@RequestParam int id) {
   userService.deleteUser(id);
   ModelAndView view = new ModelAndView("redirect:/admin/users");
   view.addObject("users", userService.getAllUsers());
   return view;
 }
 /**
  * Request method to show all users
  *
  * @param page number of page
  * @return view
  */
 @RequestMapping(value = "/users", method = RequestMethod.GET)
 public ModelAndView usersGet(@RequestParam(defaultValue = "1") int page) {
   ModelAndView view = new AdminModelAndView("users");
   int pageCount = userService.getUsersCount("");
   if (page < 1 || page > pageCount) {
     page = 1;
   }
   List<User> listUsers = userService.getUsersInRange(page, "");
   view.addObject("users", listUsers);
   view.addObject("user", new User());
   view.addObject("pageCount", pageCount);
   view.addObject("page", page);
   return view;
 }
 /**
  * Request method to get user form
  *
  * @param userId to edit
  * @return view
  */
 @RequestMapping(value = "/edit/userform/{userId}", method = RequestMethod.GET)
 public ModelAndView editUserForm(@PathVariable int userId) {
   ModelAndView view = new ModelAndView("/admin-pages/user_form");
   view.addObject("user", userService.getUser(userId));
   view.addObject("editUser", true);
   return view;
 }
 /**
  * Admin root path
  *
  * @return view
  */
 @RequestMapping(method = RequestMethod.GET)
 public ModelAndView adminHome() {
   ModelAndView view = new AdminModelAndView("admin");
   view.addObject("usersCount", userService.getAllUsers().size());
   view.addObject("productsCount", productService.getAllProducts().size());
   view.addObject("categoriesCount", categoryService.getAllCategories().size());
   view.addObject("purchasesCount", purchaseService.getAllPurchases().size());
   view.addObject("promotions", productService.getOnPromotion());
   return view;
 }
 /**
  * Request method to add user
  *
  * @param user to add
  * @return view
  */
 @RequestMapping(value = "/add/user", method = RequestMethod.POST)
 public ModelAndView addUser(@ModelAttribute User user) {
   userService.addOrUpdateUser(user);
   ModelAndView view = new ModelAndView("redirect:/admin/users");
   return view;
 }