Exemplo n.º 1
0
  public TrainingModel updateExisting(TrainingModel model) {

    Training oldTraining = trainingDao.getById(model.getId());
    Training existsWithSameName = trainingDao.getByName(model.getName());

    if (oldTraining == null || existsWithSameName != null) {
      return null;
    }

    oldTraining.setDescription(model.getDescription());
    Training saved = trainingDao.save(oldTraining);
    return saved != null ? model : null;
  }
Exemplo n.º 2
0
  public TrainingModel createNew(TrainingModel model) {
    Training exists = trainingDao.getByName(model.getName());

    if (exists != null) {
      return null;
    }

    Training training = new Training();
    training.setName(model.getName());
    training.setDescription(model.getDescription());
    training.setDateCreated(model.getDateCreated());

    Training savedTraining = trainingDao.save(training);

    if (savedTraining != null) {
      model.setId(savedTraining.getId());
      return model;
    }

    return null;
  }