コード例 #1
0
        public static Services.AddressBook.EditCorrespondent.EditCorrespondentResponse EditCorrespondent(Services.AddressBook.EditCorrespondent.EditCorrespondentRequest request)
        {
            Services.AddressBook.EditCorrespondent.EditCorrespondentResponse response = new Services.AddressBook.EditCorrespondent.EditCorrespondentResponse();

            try
            {
                DocsPaVO.utente.Utente     utente     = null;
                DocsPaVO.utente.InfoUtente infoUtente = null;

                //Inizio controllo autenticazione utente
                infoUtente = Utils.CheckAuthentication(request, "EditCorrespondent");

                utente = BusinessLogic.Utenti.UserManager.getUtenteById(infoUtente.idPeople);
                if (utente == null)
                {
                    //Utente non trovato
                    throw new PisException("USER_NO_EXIST");
                }
                //Fine controllo autenticazione utente

                if (request == null)
                {
                    throw new PisException("REQUIRED_CORRESPONDENT");
                }

                if (string.IsNullOrEmpty(request.Correspondent.Id))
                {
                    //Corrispondente non trovato
                    throw new PisException("REQUIRED_IDCORRESPONDENT");
                }

                DocsPaVO.utente.Corrispondente corr = BusinessLogic.Utenti.UserManager.getCorrispondenteBySystemIDDisabled(request.Correspondent.Id);

                if (corr == null)
                {
                    //Corrispondente non trovato
                    throw new PisException("CORRESPONDENT_NOT_FOUND");
                }

                string message = string.Empty;

                DocsPaVO.utente.DatiModificaCorr mod = new DocsPaVO.utente.DatiModificaCorr();
                mod = Utils.GetModificaCorrespondentFromPis(request.Correspondent, corr);

                bool result = BusinessLogic.Utenti.UserManager.ModifyCorrispondenteEsterno(mod, infoUtente, out message);

                if (result)
                {
                    //DocsPaVO.utente.Corrispondente corrRes = BusinessLogic.Utenti.UserManager.getCorrispondenteBySystemIDDisabled(request.Correspondent.Id);
                    //DocsPaVO.utente.Corrispondente corrRes = BusinessLogic.Utenti.UserManager.getCorrispondenteByCodRubricaNotDisabled(request.Correspondent.Code, request.Correspondent.Type == "E" ? DocsPaVO.addressbook.TipoUtente.ESTERNO : DocsPaVO.addressbook.TipoUtente.INTERNO, infoUtente);

                    DocsPaVO.utente.Corrispondente corrRes = BusinessLogic.Utenti.UserManager.getCorrispondenteByCodRubricaNotDisabled(request.Correspondent.Code, DocsPaVO.addressbook.TipoUtente.GLOBALE, infoUtente);
                    if (corrRes == null)
                    {
                        corrRes = BusinessLogic.Utenti.UserManager.getCorrispondenteByCodRubricaNotDisabled(request.Correspondent.Code, DocsPaVO.addressbook.TipoUtente.INTERNO, infoUtente);
                    }
                    if (corrRes != null && corrRes.tipoIE == "E" && !string.IsNullOrEmpty(corrRes.email))
                    {
                        if (!string.IsNullOrEmpty(corrRes.email))
                        {
                            List <DocsPaVO.utente.MailCorrispondente> casella = new List <DocsPaVO.utente.MailCorrispondente>();
                            casella.Add(new DocsPaVO.utente.MailCorrispondente()
                            {
                                Email      = corrRes.email,
                                Note       = "",
                                Principale = "1"
                            });

                            BusinessLogic.Utenti.addressBookManager.InsertMailCorrispondente(casella, corrRes.systemId);
                        }
                    }
                    response.Correspondent = Utils.GetCorrespondent(corrRes, infoUtente);
                    response.Success       = true;
                }
                else
                {
                    //Corrispondente non trovato
                    throw new PisException("CORRESPONDENT_NOT_FOUND");
                }
            }
            catch (PisException pisEx)
            {
                logger.ErrorFormat("PISException: {0}, {1}", pisEx.ErrorCode, pisEx.Description);
                response.Error = new Services.ResponseError
                {
                    Code        = pisEx.ErrorCode,
                    Description = pisEx.Description
                };

                response.Success = false;
            }
            catch (Exception ex)
            {
                logger.ErrorFormat("Eccezione Generica: APPLICATION_ERROR, {0}", ex.Message);
                response.Error = new Services.ResponseError
                {
                    Code        = "APPLICATION_ERROR",
                    Description = ex.Message
                };

                response.Success = false;
            }

            return(response);
        }
コード例 #2
0
        public SaveElementiResponse SaveElementi(SaveElementiRequest request)
        {
            SaveElementiResponse response = new SaveElementiResponse();

            DocsPaVO.utente.InfoUtente infoUtente = new DocsPaVO.utente.InfoUtente();

            try
            {
                using (DocsPaWebService ws = new DocsPaWebService())
                {
                    foreach (var elem in request.Elementi)
                    {
                        bool insertMode = (string.IsNullOrEmpty(elem.Id) || elem.Id == "0");

                        DocsPaVO.utente.Corrispondente corrispondente = null;

                        if (insertMode)
                        {
                            // Per ora, inserimento solo di unità organizzative
                            corrispondente = new DocsPaVO.utente.UnitaOrganizzativa();
                            corrispondente.tipoCorrispondente = "U";

                            corrispondente.idRegistro           = elem.IdRegistro;
                            corrispondente.codiceCorrispondente = (elem.Codice ?? string.Empty).Replace("'", "''");
                            corrispondente.codiceRubrica        = (elem.Codice ?? string.Empty).Replace("'", "''");

                            corrispondente.descrizione    = (elem.Descrizione ?? string.Empty).Replace("'", "''");
                            corrispondente.indirizzo      = (elem.Indirizzo ?? string.Empty).Replace("'", "''");
                            corrispondente.citta          = (elem.Citta ?? string.Empty).Replace("'", "''");
                            corrispondente.cap            = (elem.CAP ?? string.Empty).Replace("'", "''");
                            corrispondente.prov           = (elem.Provincia ?? string.Empty).Replace("'", "''");
                            corrispondente.nazionalita    = (elem.Nazione ?? string.Empty).Replace("'", "''");
                            corrispondente.telefono1      = (elem.Telefono ?? string.Empty).Replace("'", "''");
                            corrispondente.telefono2      = (elem.Telefono2 ?? string.Empty).Replace("'", "''");
                            corrispondente.fax            = (elem.Fax ?? string.Empty).Replace("'", "''");
                            corrispondente.codfisc        = (elem.CodiceFiscale ?? string.Empty).Replace("'", "''");
                            corrispondente.note           = (elem.Note ?? string.Empty).Replace("'", "''");
                            corrispondente.localita       = (elem.Localita ?? string.Empty).Replace("'", "''");
                            corrispondente.luogoDINascita = (elem.LuogoNascita ?? string.Empty).Replace("'", "''");
                            corrispondente.dataNascita    = (elem.DataNascita ?? string.Empty).Replace("'", "''");
                            corrispondente.titolo         = (elem.Titolo ?? string.Empty).Replace("'", "''");
                            corrispondente.email          = (elem.Email ?? string.Empty).Replace("'", "''");
                            corrispondente.dettagli       = true;

                            DocsPaVO.addressbook.DettagliCorrispondente dataSet = new DocsPaVO.addressbook.DettagliCorrispondente();
                            var rowCorrispondente = dataSet.Corrispondente.NewCorrispondenteRow();

                            rowCorrispondente.indirizzo     = (elem.Indirizzo ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.citta         = (elem.Citta ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.cap           = (elem.CAP ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.provincia     = (elem.Provincia ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.nazione       = (elem.Nazione ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.telefono      = (elem.Telefono ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.telefono2     = (elem.Telefono2 ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.fax           = (elem.Fax ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.codiceFiscale = (elem.CodiceFiscale ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.note          = (elem.Note ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.localita      = (elem.Localita ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.dataNascita   = (elem.DataNascita ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.luogoNascita  = (elem.LuogoNascita ?? string.Empty).Replace("'", "''");
                            rowCorrispondente.titolo        = (elem.Titolo ?? string.Empty).Replace("'", "''");

                            dataSet.Corrispondente.AddCorrispondenteRow(rowCorrispondente);

                            corrispondente.info = dataSet;

                            corrispondente = ws.AddressbookInsertCorrispondente(corrispondente, null, request.InfoUtente);

                            if (corrispondente == null)
                            {
                                throw new ApplicationException("Si è verificato un errore nell'inserimento dei dati dell'elemento");
                            }

                            elem.Id = corrispondente.systemId;
                            response.Elementi.Add(elem);
                        }
                        else
                        {
                            corrispondente = BusinessLogic.Utenti.UserManager.getCorrispondenteBySystemID(elem.Id);

                            DocsPaVO.utente.DatiModificaCorr datiModifica = new DocsPaVO.utente.DatiModificaCorr
                            {
                                idCorrGlobali = corrispondente.systemId,
                                descCorr      = (elem.Descrizione ?? string.Empty).Replace("'", "''"),
                                indirizzo     = (elem.Indirizzo ?? string.Empty).Replace("'", "''"),
                                citta         = (elem.Citta ?? string.Empty).Replace("'", "''"),
                                cap           = (elem.CAP ?? string.Empty).Replace("'", "''"),
                                provincia     = (elem.Provincia ?? string.Empty).Replace("'", "''"),
                                nazione       = (elem.Nazione ?? string.Empty).Replace("'", "''"),
                                telefono      = (elem.Telefono ?? string.Empty).Replace("'", "''"),
                                telefono2     = (elem.Telefono2 ?? string.Empty).Replace("'", "''"),
                                fax           = (elem.Fax ?? string.Empty).Replace("'", "''"),
                                codFiscale    = (elem.CodiceFiscale ?? string.Empty).Replace("'", "''"),
                                note          = (elem.Note ?? string.Empty).Replace("'", "''"),
                                localita      = (elem.Localita ?? string.Empty).Replace("'", "''"),
                                luogoNascita  = (elem.LuogoNascita ?? string.Empty).Replace("'", "''"),
                                dataNascita   = (elem.DataNascita ?? string.Empty).Replace("'", "''"),
                                titolo        = (elem.Titolo ?? string.Empty).Replace("'", "''"),
                                email         = (elem.Email ?? string.Empty).Replace("'", "''")
                            };

                            string newIdCorrispondente;
                            string errorMessage;

                            if (!BusinessLogic.Utenti.UserManager.ModifyCorrispondenteEsterno(datiModifica, infoUtente, out newIdCorrispondente, out errorMessage))
                            {
                                throw new ApplicationException(errorMessage);
                            }

                            if (!string.IsNullOrEmpty(newIdCorrispondente))
                            {
                                int newIdCorrispondenteAsInt;
                                if (Int32.TryParse(newIdCorrispondente, out newIdCorrispondenteAsInt))
                                {
                                    if (newIdCorrispondenteAsInt > 0)
                                    {
                                        elem.Id = newIdCorrispondenteAsInt.ToString();
                                    }
                                }
                            }

                            response.Elementi.Add(elem);
                        }
                    }
                }

                response.Success = true;
            }
            catch (Exception ex)
            {
                response         = new SaveElementiResponse();
                response.Success = false;

                if (request.TrowOnError)
                {
                    throw DocsPaUtils.Exceptions.SoapExceptionFactory.Create(ex);
                }
                else
                {
                    response.Exception = ex.Message;
                }
            }

            return(response);
        }