Exemplo n.º 1
0
        public NpceOperationResult Conferma()
        {
            SetHeaders();
            confermaRequest             = new ConfermaInvioRequest();
            confermaRequest.IdRichiesta = _visura.IdRichiesta;

            var confermaResult = proxy.Conferma(confermaRequest);
            var errors         = new List <Error>();

            foreach (var err in confermaResult.Errori)
            {
                errors.Add(new Error
                {
                    Code        = err.Codice.ToString(),
                    Description = err.Messaggio.ToString()
                });
            }

            return(new NpceOperationResult
            {
                Success = confermaResult.Esito == EsitoPostaEvo.OK,
                ErrorMessage = confermaResult.Esito != EsitoPostaEvo.OK ? confermaResult.Errori[0].Messaggio.ToString() : string.Empty,
                Errors = errors
            });
        }
Exemplo n.º 2
0
        public ResponseMOLConfirm Confirm(string requestId, Guid guidUser)
        {
            var user = _context.Users.Where(a => a.guidUser == guidUser).FirstOrDefault();

            var r = new ResponseMOLConfirm();
            RaccomandataMarketServiceClient service = getNewServiceMOL(guidUser);
            var request = new ConfermaInvioRequest();

            request.CodiceContratto = user.CodiceContrattoMOL;
            request.IdRichiesta     = requestId;

            var stato = StateRetrive(requestId, guidUser);

            if (stato.EsitoPostaEvo == EsitoPostaEvo.OK)
            {
                r.DataAccettazione   = (DateTime)stato.DataAccettazione;
                r.NumeroRaccomandata = stato.NumeroRaccomandata.Replace(" ", "");
                r.EsitoPostaEvo      = stato.EsitoPostaEvo;
            }
            else
            {
                var conferma = service.ConfermaInvio(request);
                if (conferma.Esito == EsitoPostaEvo.OK)
                {
                    r.DataAccettazione   = conferma.DataAccettazione;
                    r.NumeroRaccomandata = conferma.DestinatariRaccomandate[0].NumeroRaccomandata;
                    r.EsitoPostaEvo      = conferma.Esito;

                    var n = _context.Names.SingleOrDefault(a => a.requestId == requestId);
                    n.presaInCaricoDate = r.DataAccettazione;
                    n.codice            = r.NumeroRaccomandata;
                    n.stato             = "Presa in carico Postel";
                    n.currentState      = (int)currentState.PresoInCarico;
                    _context.SaveChanges();
                }
            }

            return(r);
        }
Exemplo n.º 3
0
        public Names sendNames(GetRecipent GetRecipent, int operationId, SenderDto sender, int userId, bool autoconfirm = false)
        {
            var n = _context.Names.SingleOrDefault(a => a.id == GetRecipent.recipient.id);

            var user     = _context.Users.SingleOrDefault(a => a.id == userId);
            var guidUser = user.guidUser;

            //PREVERIFICA BOLLETTINO
            if (GetRecipent.bulletin != null)
            {
                ControlloBollettino ctrlB = GlobalClass.verificaBollettino(GetRecipent.bulletin);
                if (!ctrlB.Valido)
                {
                    n.valid = false;
                    n.stato = "Errore nella convalida del bollettino.";
                    _context.SaveChanges();
                    return(null);
                }
            }

            RaccomandataMarketServiceClient service = getNewServiceMOL(guidUser);

            var           fileName  = GetRecipent.recipient.fileName;
            List <string> filesName = new List <string>();

            filesName.Add(fileName);

            tipoStampa ts = tipoStampa.colori;

            if (GetRecipent.recipient.tipoStampa)
            {
                ts = tipoStampa.biancoNero;
            }

            fronteRetro fr = fronteRetro.fronte;

            if (GetRecipent.recipient.fronteRetro)
            {
                fr = fronteRetro.fronteRetro;
            }

            ricevutaRitorno rr = ricevutaRitorno.no;

            if (GetRecipent.recipient.ricevutaRitorno)
            {
                rr = ricevutaRitorno.si;
            }


            Destinatario d = new Destinatario();

            d = GetDestinatarioMOL(GetRecipent.recipient);
            Destinatario[] ld = new Destinatario[1];
            ld[0] = d;
            var request = new InvioRequest();

            var intestazione = new Intestazione();

            intestazione.CodiceContratto = user.CodiceContrattoMOL;
            intestazione.Prodotto        = ProdottoPostaEvo.MOL1;

            var market = new MarketOnline();

            market.AutoConferma = autoconfirm;
            market.Destinatari  = ld;
            market.Opzioni      = GetOpzioni(ts, fr, rr);
            market.Mittente     = GetMittente(sender, user.businessName);
            market.Documenti    = getDoc(filesName, 1);

            if (GetRecipent.recipient.ricevutaRitorno)
            {
                market.DestinatarioAR = GetDestinatarioARMOL(sender);
            }

            request.Intestazione = intestazione;
            request.MarketOnline = market;

            //BOLLETTINO
            if (GetRecipent.bulletin != null)
            {
                PaginaBollettino pagina = new PaginaBollettino();
                object           b      = null;
                switch (GetRecipent.bulletin.bulletinType)
                {
                case (int)bulletinType.Bollettino451:
                    b = getBollettino451(GetRecipent.bulletin);
                    pagina.Bollettino = (Bollettino451)b;
                    break;

                case (int)bulletinType.Bollettino674:
                    b = getBollettino674(GetRecipent.bulletin);
                    pagina.Bollettino = (Bollettino674)b;
                    break;

                case (int)bulletinType.Bollettino896:
                    b = getBollettino896(GetRecipent.bulletin);
                    pagina.Bollettino = (Bollettino896)b;
                    break;
                }

                PaginaBollettino[] p = new PaginaBollettino[1];
                p[0] = pagina;
                request.MarketOnline.Bollettini = p;
            }

            try
            {
                var esito = service.Invio(request);

                if (esito.Esito == EsitoPostaEvo.OK)
                {
                    Thread.Sleep(5000);

                    var req = new ConfermaInvioRequest();
                    req.CodiceContratto = user.CodiceContrattoMOL;
                    req.IdRichiesta     = esito.IdRichiesta;

                    var conferma = service.ConfermaInvio(req);
                    if (conferma.DestinatariRaccomandate == null)
                    {
                        int i = 0;
                        do
                        {
                            Thread.Sleep(5000);
                            conferma = service.ConfermaInvio(req);
                            i++;
                        }while (conferma.DestinatariRaccomandate == null && i < 20);
                    }

                    if (conferma.Esito == EsitoPostaEvo.OK)
                    {
                        n.presaInCaricoDate = conferma.DataAccettazione;
                        n.codice            = conferma.DestinatariRaccomandate[0].NumeroRaccomandata;
                        n.stato             = "Presa in carico Poste";
                        n.currentState      = (int)currentState.PresoInCarico;
                        n.requestId         = esito.IdRichiesta;
                        n.valid             = true;
                        n.presaInCaricoDate = conferma.DataAccettazione;
                    }
                    if (conferma.Esito == EsitoPostaEvo.KO)
                    {
                        n.stato     = "Errore nella conferma di poste. Ritentare l'invio.";
                        n.requestId = null;
                        n.valid     = true;
                    }
                    _context.SaveChanges();
                }

                if (esito.Esito == EsitoPostaEvo.KO)
                {
                    n.stato = "Errore nella validazione di poste";
                    n.valid = false;
                    _context.SaveChanges();
                }
            }
            catch (Exception e)
            {
                n.valid = false;
                n.stato = "Errore nella richiesta del submit.";
                _context.SaveChanges();
                return(n);
            };

            return(n);
        }