Exemplo n.º 1
0
        /// <summary>
        /// metodo per la creazione di un nuovo corrispondente
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Response</returns>
        public Services.AddressBook.AddCorrespondent.AddCorrespondentResponse AddCorrespondent(Services.AddressBook.AddCorrespondent.AddCorrespondentRequest request)
        {
            logger.Info("BEGIN");
            Services.AddressBook.AddCorrespondent.AddCorrespondentResponse response = Manager.AddressBookManager.AddCorrespondent(request);

            Utils.CheckFaultException(response);
            logger.Info("END");

            return(response);
        }
Exemplo n.º 2
0
        public static Services.AddressBook.AddCorrespondent.AddCorrespondentResponse AddCorrespondent(Services.AddressBook.AddCorrespondent.AddCorrespondentRequest request)
        {
            Services.AddressBook.AddCorrespondent.AddCorrespondentResponse response = new Services.AddressBook.AddCorrespondent.AddCorrespondentResponse();
            try
            {
                DocsPaVO.utente.Utente     utente     = null;
                DocsPaVO.utente.InfoUtente infoUtente = null;

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

                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.Correspondent == null)
                {
                    //Corrispondente non trovato
                    throw new PisException("REQUIRED_CORRESPONDENT");
                }

                if (string.IsNullOrEmpty(request.Correspondent.CorrespondentType) || (!request.Correspondent.CorrespondentType.Equals("U") && !request.Correspondent.CorrespondentType.Equals("P")))
                {
                    //Inserire il tipo U o P
                    throw new PisException("REQUIRED_CORRESPONDENTTYPE");
                }

                if (request.Correspondent.CorrespondentType.Equals("U"))
                {
                    if (string.IsNullOrEmpty(request.Correspondent.Description))
                    {
                        //richiesta descrizione
                        throw new PisException("REQUIRED_DESCRIPTION_CORREPONDENT");
                    }
                }

                if (request.Correspondent.CorrespondentType.Equals("P"))
                {
                    if (string.IsNullOrEmpty(request.Correspondent.Name) || string.IsNullOrEmpty(request.Correspondent.Surname))
                    {
                        //richiesta descrizione
                        throw new PisException("REQUIRED_N_S_CORREPONDENT");
                    }
                }

                DocsPaVO.utente.Corrispondente corrResult   = null;
                Domain.Correspondent           corrResponse = null;

                //Posso creare solo esterni
                request.Correspondent.Type = "E";

                DocsPaVO.utente.Corrispondente corr = Utils.GetCorrespondentFromPisNewInsert(request.Correspondent, infoUtente);


                if (corr != null && !string.IsNullOrEmpty(corr.tipoCorrispondente) && !corr.tipoCorrispondente.Equals("O") && !BusinessLogic.Utenti.addressBookManager.VerificaInserimentoCorrispondente(corr, null))
                {
                    //Codice corrispondente già presente
                    throw new PisException("CODE_CORRESPONDENT_EXISTS");
                }

                corrResult = BusinessLogic.Utenti.addressBookManager.insertCorrispondente(corr, null);

                corrResponse = Utils.GetCorrespondent(corrResult, infoUtente);

                if (corrResponse != null)
                {
                    List <DocsPaVO.utente.MailCorrispondente> casella = new List <DocsPaVO.utente.MailCorrispondente>();
                    casella.Add(new DocsPaVO.utente.MailCorrispondente()
                    {
                        Email      = corrResult.email,
                        Note       = "",
                        Principale = "1"
                    });

                    BusinessLogic.Utenti.addressBookManager.InsertMailCorrispondente(casella, corrResult.systemId);
                    response.Correspondent = corrResponse;
                    response.Success       = true;
                }
                else
                {
                    //Corrispondente non trovato
                    throw new PisException("USER_NO_EXIST");
                }
            }
            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);
        }