private PartModel bindPartModel(Part part) {
   PartModel model = null;
   try {
     if (part != null && part.getPartNumber().length() > 0) {
       model = new PartModel();
       model.setCountNeeded(part.getCountNeeded());
       model.setName(part.getName());
       model.setPartNumber(part.getPartNumber());
       if (part.getPhoto() != null) {
         model.setPhoto(part.getPhoto());
       }
       model.setStockCount(part.getStockCount());
     }
   } catch (NullPointerException e) {
     throw new IllegalArgumentException(e.getMessage());
   }
   return model;
 }
  private Part bindPart(PartModel model) {
    Part part = null;
    try {
      if (model != null && model.getPartNumber().length() > 0) {
        part = entityManager.find(Part.class, model.getPartNumber());
        if (part != null) {
          part.setName(model.getName());
          part.setCountNeeded(model.getCountNeeded());
          part.setStockCount(model.getStockCount());
          if (model.getPhoto() != null) {
            part.setPhoto(model.getPhoto());
          }
          part.setPhoto(model.getPhoto());
        } else if (part == null) {
          part = new Part();
          part.setName(model.getName());
          part.setPartNumber(model.getPartNumber());
          part.setCountNeeded(model.getCountNeeded());
          part.setStockCount(model.getStockCount());
          if (model.getPhoto() != null) {
            part.setPhoto(model.getPhoto());
          }
          part.setPhoto(model.getPhoto());
        }
      }
    } catch (NullPointerException e) {
      throw new IllegalArgumentException(e.getMessage());
    }

    return part;
  }