public boolean save(View view, Model model) {
DBHelper.openConnection();
boolean saved = false;
String errors = "";
Staff st = (Staff) model;
String profilePicturePath = st.getProfilePicturePath();
if(st.save()) {
saved = true;
// Upload profile picture if provided
if(!profilePicturePath.equals("")) {
File tmpFile = new File(profilePicturePath);
if(tmpFile.exists() && tmpFile.isFile()) {
if(FileHelper.fileSizeInMB(tmpFile) < FileHelper.UPLOAD_LIMIT) {
try {
String profilePicture = FileHelper.absolutePathToLocalFilename(profilePicturePath, (String)st.get("username"));
FileUtils.copyFile(new File(profilePicturePath), new File(FileHelper.PROFILE_PIC_DIR + profilePicture));
st.set("profile_picture", profilePicture);
st.save();
} catch (IOException ex) {
errors += "Error saving profile picture";
}
} else {
errors += "The upload limit is " + FileHelper.UPLOAD_LIMIT + "MB";