}
try{
respBuying = coreManager.save(Buying.class, b);
}catch (Exception e) {
SgwtRestErrorResponse resp = new SgwtRestErrorResponse(SgwtRestResponseBase.RESPONSE_FAILURE);
resp.addError("exception", e.getMessage());
return resp;
}
}else if(request.getOperationType() == OPERATION_TYPE.ADD){
Double buyingPrice = RequestUtil.getDouble(request.getData().get("buyingPrice"));
Double disc1 = RequestUtil.getDouble(request.getData().get("disc1"));
Double disc2 = RequestUtil.getDouble(request.getData().get("disc2"));
Double disc3 = RequestUtil.getDouble(request.getData().get("disc3"));
Double disc4 = RequestUtil.getDouble(request.getData().get("disc4"));
Boolean taxIncluded = RequestUtil.getBoolean(request.getData().get("taxIncluded"));
Double discPrice = RequestUtil.getDouble(request.getData().get("discPrice"));
Integer measurementSelectionId = RequestUtil.getInteger(request.getData().get("measurementSelectionId"));
Integer supplierId = RequestUtil.getInteger(request.getData().get("supplierId"));
Buying b = new Buying();
b.setId(id);
b.setBuyingPrice(buyingPrice);
b.setDisc1(disc1);
b.setDisc2(disc2);
b.setDisc3(disc3);
b.setDisc4(disc4);
b.setTaxIncluded(taxIncluded);
b.setDiscPrice(discPrice);
Measurement selm = coreManager.get(Measurement.class, measurementSelectionId);
b.setMeasurement(selm);
Supplier supp = coreManager.get(Supplier.class, supplierId);
b.setSupplier(supp);
Product prod = coreManager.get(Product.class, id);
b.setProduct(prod);
try{
respBuying = coreManager.save(Buying.class, b);
}catch (Exception e) {
e.printStackTrace();
SgwtRestErrorResponse resp = new SgwtRestErrorResponse(-1);
resp.addError("exception", e.getMessage());
return resp;
}
}