AdminBean adminBean = getAdminBean(request);
Site site = adminBean.getSite();
String siteId = site.getSiteId();
initSiteProfiles(form, site);
Coupon coupon = CouponDAO.load(siteId, Format.getLong(form.getCouponId()));
form.setCouponCode(form.getCouponCode().toUpperCase());
ActionMessages errors = validate(form, insertMode, site.getSiteId());
if (errors.size() != 0) {
saveMessages(request, errors);
return mapping.findForward("error");
}
if (insertMode) {
coupon = new Coupon();
coupon.setSite(site);
coupon.setCouponTotalUsed(Integer.valueOf(0));
coupon.setRecCreateBy(adminBean.getUser().getUserId());
coupon.setRecCreateDatetime(new Date(System.currentTimeMillis()));
}
if (form.isSiteProfileClassDefault() && form.isSiteCurrencyClassDefault()) {
saveDefault(coupon, form, adminBean);
}
else {
if (!form.isSiteProfileClassDefault()) {
saveLanguage(coupon, form, adminBean);
}
if (!form.isSiteCurrencyClassDefault()) {
saveCurrency(coupon, form, adminBean);
}
}
if (insertMode) {
em.persist(coupon);
}
form.setCouponTotalUsed(Format.getInt(coupon.getCouponTotalUsed()));
form.setMode("U");
form.setCouponId(coupon.getCouponId().toString());
FormUtils.setFormDisplayMode(request, form, FormUtils.EDIT_MODE);
return mapping.findForward("success");
}