@RequestMapping(value = "/UserModifiedSuccessfully", method = RequestMethod.POST) public ModelAndView post( @RequestParam("modUseradd1") String textAddress1, @RequestParam("modUseradd2") String textAddress2, @RequestParam("modUsercity") String city, @RequestParam("modUserstate") String state, @RequestParam("modUserzipcode") String zipCode, @RequestParam("modUserphone") String phoneNumber, @RequestParam("modUsercell") String cellNumber, @RequestParam("modUseremail") String email, @RequestParam("modUserdept") String dept, @RequestParam("designation") String designation, HttpSession sessionID) throws SQLException { String modUser = (String) sessionID.getAttribute("modUser"); /*if(userName == null) { return new ModelAndView("index"); }*/ InternalUserDAO internalUserDAO1 = new InternalUserDAO(); InternalUser internalUser = internalUserDAO1.findInternalUser(modUser); internalUser.setAddress1(textAddress1); internalUser.setAddress2(textAddress2); internalUser.setCity(city); internalUser.setState(state); internalUser.setZipcode(zipCode); internalUser.setPhoneNumber(phoneNumber); internalUser.setCellNumber(cellNumber); internalUser.setEmail(email); internalUser.setDepartment(dept); internalUser.setUserName(modUser); internalUser.setDesignation(designation); internalUserDAO1.persist(internalUser); String modifiedUserName = internalUser.getFirstName() + internalUser.getLastName(); InternalUserTransactionDAO internalUserTransactionDAO = new InternalUserTransactionDAO(); String operation = "Modified"; InternalUserTransaction newTransaction = new InternalUserTransaction( (String) sessionID.getAttribute("userName"), operation, internalUser.getFirstName(), internalUser.getLastName()); internalUserTransactionDAO.persist(newTransaction); return new ModelAndView("UserModifiedSuccessfully", "message", modifiedUserName); }
@RequestMapping(value = "/DeleteSubordinate", method = RequestMethod.POST) public ModelAndView deleteSubordinates( @RequestParam("delUserame") String userToBeDeletedUserName, HttpSession sessionID) throws SQLException { InternalUserDAO internalUserDAO = new InternalUserDAO(); InternalUser userToBeDeleted = internalUserDAO.findInternalUser(userToBeDeletedUserName); if (userToBeDeleted.getFirstDelete() == 1) { internalUserDAO.delete(userToBeDeleted); InternalUserTransactionDAO internalUserTransactionDAO = new InternalUserTransactionDAO(); // Added a transaction to the Internal User Transaction Table. String operation = "Deleted"; InternalUserTransaction newTransaction = new InternalUserTransaction( (String) sessionID.getAttribute("userName"), operation, userToBeDeleted.getFirstName(), userToBeDeleted.getLastName()); internalUserTransactionDAO.persist(newTransaction); // delete from ToDo Table also. ToDoDAO toDoDAO = new ToDoDAO(); toDoDAO.delete( toDoDAO.findAParticularToDo( (String) sessionID.getAttribute("userName"), userToBeDeleted.getUserName(), "Delete")); return new ModelAndView( "DeleteSubordinate", "message", "The Employee has been deleted from the Records"); } else { userToBeDeleted.setFirstDelete(1); internalUserDAO.persist(userToBeDeleted); // String manager = userToBeDeleted.getManager(); InternalUser loggedInUser = internalUserDAO.findInternalUser((String) sessionID.getAttribute("userName")); String manager = loggedInUser.getManager(); if (loggedInUser.getDesignation().equalsIgnoreCase("corporate")) { // corporrate people have authority to directly delete a employee internalUserDAO.delete(userToBeDeleted); // Added a transaction to the Internal User Transaction Table. InternalUserTransactionDAO internalUserTransactionDAO = new InternalUserTransactionDAO(); String operation = "Deleted"; InternalUserTransaction newTransaction = new InternalUserTransaction( (String) sessionID.getAttribute("userName"), operation, userToBeDeleted.getFirstName(), userToBeDeleted.getLastName()); internalUserTransactionDAO.persist(newTransaction); return new ModelAndView( "DeleteSubordinate", "message", "The Employee has been deleted from the Records"); } else { // Have to Finalize based on what Manager Name is given.Right Now its on First Name basis /*String firstName = manager.substring(0, manager.indexOf(" ")); String lastName = manager.substring(manager.indexOf(" "));*/ InternalUser userNameManager = internalUserDAO.findInternalUserByName(manager /*, lastName*/); String actioneer = userNameManager.getUserName(); ToDo newEntry = new ToDo( actioneer, userToBeDeletedUserName, 0, "Delete", "Requesting second Authorization for Deletion"); ToDoDAO toDoDAO = new ToDoDAO(); toDoDAO.persist(newEntry); return new ModelAndView( "DeleteSubordinate", "message", "Notification has been send to Manager for approval for deletion"); } } }