/**
  * Disable a category
  *
  * @param instance
  */
 @Override
 public boolean delete(CategoryOfProduct instance) {
   try {
     instance.setIsActive(false);
     if (super.update(instance)) {
       DiaryEntityManager.createLog("Deleted category \"" + instance.getCateName() + "\"");
       return true;
     } else {
       return false;
     }
   } catch (Exception ex) {
     System.out.println("Failed to disable category: " + ex.getMessage());
     return false;
   }
 }
  /**
   * Add new category
   *
   * @param instance
   * @return true if succeeded, else false
   */
  public boolean addNew(CategoryOfProduct instance) {
    if (instance.getCateName().isEmpty()) {
      return false;
    }
    try {
      if (find(instance.getCateName()) != null) {
        System.err.println("Category already exists!");
        return false;
      }

      super.insert(instance);
      DiaryEntityManager.createLog("Created category \"" + instance.getCateName() + "\"");
      return true;
    } catch (Exception ex) {
      System.out.println("Failed to add new category: " + ex.getMessage());
      return false;
    }
  }
  /**
   * Update category's information. If the category doesn't exist, create a new one.
   *
   * @param instance new information
   * @return
   */
  public boolean edit(CategoryOfProduct instance) {
    if (instance.getCateName().isEmpty()) {
      return false;
    }

    try {
      CategoryOfProduct search = find(instance.getCateName());
      // Neu doi ten thi phai bao dam la ten nay chua ton tai
      if (search == null || Objects.equals(search.getId(), instance.getId())) {
        super.update(instance);
        DiaryEntityManager.createLog("Edited category \"" + instance.getCateName() + "\"");
        return true;
      }

      return false;

    } catch (Exception ex) {
      System.out.println("Failed to update category: " + ex.getMessage());
      return false;
    }
  }