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); }
public async Task <Names> sendNames(GetRecipent GetRecipent, int operationId, SenderDto sender, int userId) { 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); } } ROLServiceSoapClient service = new ROLServiceSoapClient(); service = getNewServiceRol(guidUser); var fileName = GetRecipent.recipient.fileName; List <string> filesName = new List <string>(); filesName.Add(fileName); var requestId = getRequestId(guidUser); tipoStampa ts = tipoStampa.colori; if (GetRecipent.recipient.tipoStampa) { ts = tipoStampa.biancoNero; } fronteRetro fr = fronteRetro.fronte; if (GetRecipent.recipient.fronteRetro) { fr = fronteRetro.fronteRetro; } Destinatario d = new Destinatario(); d = GetDestinatarioRol(GetRecipent.recipient); Destinatario[] ld = new Destinatario[1]; ld[0] = d; ROLSubmit rs = new ROLSubmit(); rs.Destinatari = ld; rs.Opzioni = GetOpzioniRol(ts, fr); rs.Mittente = GetMittente(sender); rs.NumeroDestinatari = 1; rs.Documento = getDoc(filesName, 1); //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; } PaginaBollettinoBase[] p = new PaginaBollettinoBase[1]; p[0] = pagina; rs.PagineBollettini = p; } //RICEVUTA DI RITORNO if (GetRecipent.recipient.ricevutaRitorno) { DatiRicevuta dr = new DatiRicevuta(); dr.Nominativo = rs.Mittente.Nominativo; rs.DatiRicevuta = dr; } rs.Nazionale = (GetRecipent.recipient.state.ToUpper() == "ITALIA" ? "true" : "false"); InvioResult esito = new InvioResult(); try { esito = service.Invio(requestId, user.businessName, rs); if (esito.CEResult.Type != "I") { n.valid = false; n.stato = esito.CEResult.Description; _context.SaveChanges(); return(n); } n.requestId = esito.IDRichiesta; n.guidUser = esito.GuidUtente; _context.SaveChanges(); } catch (Exception e) { n.valid = false; n.stato = "Errore nella richiesta del submit."; _context.SaveChanges(); return(n); }; return(n); }
public async Task <bool> Sync() { var namesGrouped = _context.Names .Where(a => a.valid == true) .Where(a => a.currentState == 0) .Where(a => a.requestId == null) .Where(a => a.Operations.demoOperation == false) .Where(a => a.Operations.complete == true) .Where(a => a.locked == false) .Take(30) .GroupBy(a => a.operationId) .ToList(); var guid = Guid.NewGuid(); LockUnlockNames(namesGrouped, true, guid); try { for (var i = 0; i < namesGrouped.Count; i++) { var list = new List <Names>(); var names = namesGrouped[i].ToList(); foreach (var n in names) { var sender = _context.Senders.SingleOrDefault(a => a.operationId == n.Operations.id); var bulletin = _context.Bulletins.Where(a => a.namesId == n.id).ToList(); Bulletins b = null; if (bulletin.Count() > 0) { b = bulletin[0]; } var senderDto = Mapper.Map <Senders, SenderDto>(sender); var gr = new GetRecipent() { recipient = Mapper.Map <Names, NamesDto>(n), bulletin = Mapper.Map <Bulletins, BulletinsDtos>(b) }; switch (n.Operations.operationType) { case (int)operationType.MOL: var m = new MOLController(); var newNamesMol = m.sendNames(gr, n.operationId, senderDto, n.Operations.userId); if (newNamesMol.valid) { list.Add(newNamesMol); } break; case (int)operationType.COL: var c = new COLController(); var newNamesCol = c.sendNames(gr, n.operationId, senderDto, n.Operations.userId); if (newNamesCol.valid) { list.Add(newNamesCol); } break; case (int)operationType.ROL: var r = new RolController(); var newNamesRol = await r.sendNames(gr, n.operationId, senderDto, n.Operations.userId); if (newNamesRol.valid) { list.Add(newNamesRol); } break; } } if (list.Count > 0) { switch (names[0].Operations.operationType) { case (int)operationType.MOL: var m = new MOLController(); break; case (int)operationType.COL: var c = new COLController(); break; case (int)operationType.ROL: var r = new RolController(); await r.ValorizzaConfirm(list, names[0].Operations.Users.guidUser); break; } } } } catch (Exception e) { } LockUnlockNames(namesGrouped, false, guid); return(true); }