Example #1
0
  @Check("isAdmin")
  public static void edit(String idSession) {
    Session sessions = Session.getSessionById(Long.parseLong(idSession));
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");
    String dateDebut = sdf.format(sessions.dateDepart);
    String dateFin = sdf.format(sessions.dateFin);

    List<ProduitType> listProduitTypes = Arrays.asList(ProduitType.values());

    Circuit tempCircuit = sessions.circuit;

    sessions.circuit = null;
    sessions.save();

    sessions = Session.getSessionById(Long.parseLong(idSession));
    sessions.circuit = tempCircuit;

    boolean isAvailableCircuit =
        Circuit.isAvailableCircuitByAgence(sessions.dateDepart, sessions.dateFin, sessions.agence);

    Agence agence = sessions.agence;
    render(
        "Sessions/add.html",
        sessions,
        dateDebut,
        dateFin,
        isAvailableCircuit,
        listProduitTypes,
        agence);
  }
Example #2
0
  @Check("isAdmin")
  public static void save() {
    Session session;
    String idSession = params.get("session.id");
    System.out.println(idSession);
    if (idSession != null && !idSession.equals("")) {
      session = Session.getSessionById(Long.parseLong(params.get("session.id")));
    } else {
      session = new Session();
    }

    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm");

    try {
      session.dateDepart = sdf.parse(params.get("session.dateDebut"));
      session.dateFin = sdf.parse(params.get("session.dateFin"));
    } catch (ParseException ex) {
      Logger.getLogger(Disponibilites.class.getName()).log(Level.SEVERE, null, ex);
    }

    session.commentaires = params.get("session.commentaires");
    String nbPlace = params.get("session.nbMaxPlaces");
    if (nbPlace != null && !nbPlace.equals("")) {
      session.nbMaxPlaces = Integer.parseInt(nbPlace);
    }

    Agence agence = Agence.getAgenceById(Long.parseLong(params.get("session.agence").toString()));
    session.agence = agence;
    String resultCircuit = params.get("session.circuit");
    if (resultCircuit.equals("indisponible") || resultCircuit.equals("false")) {
      session.circuit = null;
    } else {
      session.circuit = Circuit.getCircuitByAgence(agence);
    }
    session.typeProduit = ProduitType.valueOf(params.get("session.type"));
    session.employe = Employe.getEmployeById(Long.parseLong(params.get("session.employe")));
    session.vehicule = Vehicule.getVehiculeById(Long.parseLong(params.get("session.vehicule")));

    validation.valid(session);

    if (Validation.hasErrors()) {
      params.flash();
      Validation.keep();
      if (idSession != null && !idSession.equals("")) {
        Sessions.edit(idSession);
      } else {
        Sessions.add(
            formatDateToCalendar(params.get("session.dateDebut").toString()),
            formatDateToCalendar(params.get("session.dateFin").toString()),
            params.get("session.agence").toString());
      }
    } else {
      session.save();
      Sessions.show();
    }
  }
Example #3
0
 @Check("isAdmin")
 public static void move() {
   try {
     Session session = Session.getSessionById(Long.parseLong(params.get("id")));
     SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyyHHmm");
     session.dateDepart = sdf.parse(params.get("start"));
     session.dateFin = sdf.parse(params.get("end"));
     session.save();
   } catch (ParseException ex) {
     Logger.getLogger(Disponibilites.class.getName()).log(Level.SEVERE, null, ex);
   }
 }