Package org.magicbox.controller

Source Code of org.magicbox.controller.UtentiController

/*
* Copyright Massimiliano Dessi' (desmax74@yahoo.it)
*
* Licensed for non-commercial use,
* under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.magicbox.admin.service.CentriManager;
import org.magicbox.controller.util.WebUtils;
import org.magicbox.domain.CentroLight;
import org.magicbox.dto.Page;
import org.magicbox.exception.UtenteNonTrovatoException;
import org.magicbox.service.UtentiManager;
import org.magicbox.util.Constant;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

/**
* Controller per gestione utenti
*
* @author Massimiliano Dessì (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
public class UtentiController extends MultiActionController {

    public ModelAndView elenco(HttpServletRequest req, HttpServletResponse res) throws Exception {

        CentroLight centro = centriManager.getInfoCentro(WebUtils.getIdCentro(req));
        Page page = WebUtils.getPagina(req, centro.getNumeroDonatori(), utentiManager.getNumeroUtentiPerPagina());

        ModelAndView mav = new ModelAndView("donors/elencoDonatori");
        mav.addObject(Constant.ELENCO_DONATORI, utentiManager.getUtentiCentro(centro.getId(), page.getPagina()));
        mav.addObject(Constant.PAGE_VO, page);
        mav.addObject(Constant.CENTRO_DONAZIONE, centro);
        return mav;
    }

    public ModelAndView conferma(HttpServletRequest req, HttpServletResponse res) throws Exception {

        long id = ServletRequestUtils.getLongParameter(req, Constant.ID, 0);
        if (id == 0) {
            throw new UtenteNonTrovatoException();
        } else {
            return new ModelAndView("donors/confermaEliminazioneDonatore", Constant.DONOR, utentiManager.getUtente(id, WebUtils.getIdCentro(req)));
        }
    }

    public ModelAndView elimina(HttpServletRequest req, HttpServletResponse res) throws Exception {

        long id = ServletRequestUtils.getLongParameter(req, Constant.ID, 0);
        if (id == 0) {
            throw new UtenteNonTrovatoException();
        } else {
            String msg = Constant.MSG_ELIMINAZIONE_NO;
            if (utentiManager.deleteUtente(id, WebUtils.getIdCentro(req))) {
                msg = Constant.MSG_ELIMINAZIONE_OK;
            }
            return new ModelAndView(Constant.FORWARD_ELENCO_DONORS, Constant.MSG, msg);
        }
    }

    public ModelAndView dettaglio(HttpServletRequest req, HttpServletResponse res) throws Exception {

        long id = ServletRequestUtils.getLongParameter(req, Constant.ID, 0);
        if (id == 0) {
            throw new UtenteNonTrovatoException();
        } else {
            return new ModelAndView("donors/dettaglioDonatore", Constant.DONOR, utentiManager.getUtente(id, WebUtils.getIdCentro(req)));
        }
    }

    public void setCentriManager(CentriManager centriManager) {
        this.centriManager = centriManager;
    }

    public void setUtentiManager(UtentiManager utentiManager) {
        this.utentiManager = utentiManager;
    }

    private CentriManager centriManager;
    private UtentiManager utentiManager;
}
TOP

Related Classes of org.magicbox.controller.UtentiController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.