Subversion Repositories WebE

Compare Revisions

Last modification

Regard whitespace Rev 21 → Rev 22

/trunk/src/ch/ffhs/webE/dao/UserDAO.java
9,4 → 9,5
List<User> listUser();
void saveUser(User user);
User searchUsername(String username);
void deleteUser(int userId);
}
/trunk/src/ch/ffhs/webE/dao/UserDAOImpl.java
19,13 → 19,13
@SuppressWarnings("unchecked")
@Override
public List<User> listUser() {
List<User> courses = null;
List<User> user = null;
try {
courses = session.createQuery("from User").list();
user = session.createQuery("from User").list();
} catch (Exception e) {
e.printStackTrace();
}
return courses;
return user;
}
 
@Override
39,19 → 39,34
}
/**
* Used to delete a user.
*/
@Override
public void deleteUser(int userId) {
try {
User user = (User) session.get(User.class, userId);
session.delete(user);
} catch (Exception e) {
transaction.rollback();
e.printStackTrace();
}
}
 
/**
* Returns a single user with this user name (used for login)
* @param username: String - entire user name
* @return User: Returns a user object if something is found. If not, null is returned
*
* @param username
* : String - entire user name
* @return User: Returns a user object if something is found. If not, null
* is returned
*/
public User searchUsername(String username) {
User user = null;
try {
user = (User) session.createQuery(
"FROM User " +
"WHERE username = :username")
.setParameter("username", username)
.uniqueResult();
user = (User) session
.createQuery("FROM User " + "WHERE username = :username")
.setParameter("username", username).uniqueResult();
} catch (Exception e) {
//TODO: Log error
}
/trunk/src/ch/ffhs/webE/action/UserAction.java
3,6 → 3,11
import java.util.ArrayList;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.ServletActionContext;
 
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import ch.ffhs.webE.dao.UserDAO;
23,18 → 28,12
return user;
}
public String add()
{
public String add() {
userDAO.saveUser(user);
return SUCCESS;
}
public String addForm() {
return SUCCESS;
}
public String list()
{
public String list() {
userList = userDAO.listUser();
return SUCCESS;
}
55,4 → 54,11
this.userList = userList;
}
 
public String delete() {
HttpServletRequest request = (HttpServletRequest) ActionContext
.getContext().get(ServletActionContext.HTTP_REQUEST);
userDAO.deleteUser(Integer.parseInt(request.getParameter("id")));
return SUCCESS;
}
 
}