private async Task <byte[]> GenerateFufXml(IHttpClient httpClient, Sender senderToSend) { var request = CreateGenerateFufRequest(); var responseMessage = await httpClient.PostAsJsonAsync("generate-fuf-ssch?windows1251=true", request); return(await responseMessage.Content.ReadAsByteArrayAsync()); GenerateFufRequest CreateGenerateFufRequest() { var certificateDto = senderToSend.Certificate == null ? null : new CertificateDto(senderToSend.Certificate.Value.ToString()); var senderDto = new SenderDto( senderToSend.Inn, certificateDto, senderToSend.Kpp, senderToSend.OrgName ); var payerDto = payer == null ? null : new PayerDto( payer.Inn, payer.Name, payer.Kpp == null ? null : new OrganizationInfoDto(payer.Kpp), payer.ChiefFullName ); return(new GenerateFufRequest(senderDto, payerDto, warrant)); } }
private static Mittente GetMittente(SenderDto sender) { Mittente Mittente = new Mittente(); Nominativo Nominativo = new Nominativo(); Indirizzo Indirizzo = new Indirizzo(); Nominativo.CAP = sender.cap; Nominativo.Citta = sender.city; Nominativo.Cognome = sender.surname; Nominativo.Nome = sender.name; Nominativo.Provincia = sender.province; Nominativo.Stato = sender.state; Nominativo.RagioneSociale = sender.businessName; Indirizzo.DUG = sender.dug; Indirizzo.NumeroCivico = sender.houseNumber; Indirizzo.Toponimo = sender.address; Indirizzo.Esponente = string.Empty; Nominativo.Telefono = string.Empty; Nominativo.TipoIndirizzo = NominativoTipoIndirizzo.NORMALE; Nominativo.UfficioPostale = ""; Nominativo.Zona = string.Empty; Nominativo.ComplementoIndirizzo = string.Empty; Nominativo.CasellaPostale = ""; Nominativo.ComplementoNominativo = string.Empty; Nominativo.Frazione = string.Empty; Nominativo.Indirizzo = Indirizzo; Mittente.Nominativo = Nominativo; Mittente.InviaStampa = false; return(Mittente); }
private static Mittente GetMittente(SenderDto sender, string businessName) { Mittente m = new Mittente(); m.Nominativo = businessName; m.ComplementoIndirizzo = ""; m.ComplementoNominativo = ""; m.Indirizzo = sender.dug + " " + sender.address + " " + sender.houseNumber; m.Cap = sender.cap; m.Comune = sender.city; m.Provincia = sender.province; m.Nazione = sender.state; return(m); }
private static DestinatarioAR GetDestinatarioARMOL(SenderDto name, int?index = 1) { DestinatarioAR n = new DestinatarioAR(); n.Nominativo = name.businessName + " " + name.surname + " " + name.name; n.ComplementoNominativo = ""; n.ComplementoIndirizzo = ""; n.Indirizzo = name.dug + " " + name.address + " " + name.houseNumber; n.Cap = name.cap; n.Comune = name.city; n.Provincia = name.province; n.Nazione = name.state; 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 <GetNumberOfCheckedNames> CheckAllFiles([FromUri] Guid guidUser, [FromBody] ObjectSubmit senderRecipients, [FromUri] bool tsc, [FromUri] bool frc, [FromUri] bool rrc, [FromUri] int userId) { SenderDto sender = new SenderDto(); sender = senderRecipients.sender; List <GetRecipent> GetRecipents = senderRecipients.recipients; GetNumberOfCheckedNames ncn = new GetNumberOfCheckedNames(); List <GetCheckedNames> lgcn = new List <GetCheckedNames>(); //MULTIPLE USERS var users = _context.Users.Where(a => a.guidUser == guidUser); //ERRORE GUID if (users.Count() == 0) { ncn.numberOfValidNames = 0; ncn.state = "Utente non riconosiuto"; return(ncn); } //UTENTE INSERITORE var u = new Users(); if (userId > 0) { u = users.SingleOrDefault(a => a.id == userId); } else { u = users.SingleOrDefault(a => a.parentId == 0); } //ERRORE MITTENTE ControlloMittente ctrlM = GlobalClass.verificaMittente(senderRecipients.sender); if (!ctrlM.Valido) { ncn.numberOfValidNames = 0; ncn.state = "Mittente non valido"; return(ncn); } OperationsController oc = new OperationsController(); OperationsDto op = new OperationsDto(); op.date = DateTime.Now; op.name = " Operazione del " + DateTime.Now.ToString("dd/MM/yyyy"); op.userId = u.id; op.operationType = (int)operationType.MOL; op.demoOperation = u.demoUser; op.areaTestOperation = u.areaTestUser; op.complete = false; int operationId = OperationsController.CreateItem(op); tipoStampa ts = tipoStampa.colori; if (tsc) { ts = tipoStampa.biancoNero; } fronteRetro fr = fronteRetro.fronte; if (frc) { fr = fronteRetro.fronteRetro; } ricevutaRitorno rr = ricevutaRitorno.si; if (rrc) { rr = ricevutaRitorno.no; } createFeatures(ts, fr, rr, operationId); SenderDtos ss = Mapper.Map <SenderDto, SenderDtos>(sender); ss.operationId = operationId; int senderId = SenderController.CreateItem(ss); int validNames = 0; foreach (var GetRecipent in GetRecipents.ToList()) { int id = (int)GetRecipent.recipient.id; var b = _context.Bulletins.Where(a => a.namesListsId == id).ToList(); if (b.Count() > 0) { GetRecipent.bulletin = Mapper.Map <Bulletins, BulletinsDtos>(b[0]); } ; NamesDtos nos = Mapper.Map <NamesDto, NamesDtos>(GetRecipent.recipient); nos.operationId = operationId; nos.requestId = null; nos.guidUser = null; nos.valid = true; nos.fronteRetro = Convert.ToBoolean(fr); nos.ricevutaRitorno = Convert.ToBoolean(rr); nos.tipoStampa = Convert.ToBoolean(ts); nos.insertDate = DateTime.Now; nos.currentState = (int)currentState.inAttesa; var nc = new NamesController(); int idName = nc.CreateItem(nos, u.userPriority); if (GetRecipent.bulletin != null) { BulletinsDto bos = Mapper.Map <BulletinsDtos, BulletinsDto>(GetRecipent.bulletin); bos.namesId = idName; BulletinsController.CreateItem(bos); } validNames++; GetCheckedNames gcn = new GetCheckedNames() { name = nos, valid = true, price = new Prices() }; lgcn.Add(gcn); } ncn.numberOfValidNames = validNames; ncn.checkedNames = lgcn; ncn.state = "Inserimento valido!"; ncn.valid = true; ncn.operationId = operationId; return(ncn); }
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); }
private record GenerateFufRequest(SenderDto sender, PayerDto?payer, WarrantInfo?warrant);
public ControlloMittente() { sender = new SenderDto(); Valido = true; Errore = ""; }
public static ControlloMittente verificaMittente(SenderDto sender) { var r = File.ReadAllText(HttpContext.Current.Server.MapPath("~/json/comuniItaliani.json")); var comuni = JsonConvert.DeserializeObject <List <ComuniItaliani> >(r); SenderDto s = sender; ControlloMittente ctrl = new ControlloMittente(); ctrl.sender = sender; string Cap = sender.cap.Replace(" ", ""); var comune = comuni.Where(c => c.cap.ToString().Contains(Cap)); int i = comune.Count(); // CONTROLLO CAP crt crt = verificaCap(Cap, i); if (!crt.Valido) { ctrl.Valido = crt.Valido; ctrl.Errore = crt.Errore + " - Mittente"; } // CONTROLLO RAGIONE SOCIALE / NOME E COGNOME crt crtR = verificaRagioneSociale(s.businessName, s.name, s.surname); if (!crtR.Valido) { ctrl.Valido = crtR.Valido; ctrl.Errore = crtR.Errore + " - Mittente"; } // CONTROLLO INDIRIZZO crt crtA = verificaIndirizzo(s.dug, s.address, s.houseNumber); if (!crtA.Valido) { ctrl.Valido = crtA.Valido; ctrl.Errore = crtA.Errore + " - Mittente"; } // CONTROLLO CITTA' crt crtC = verificaCitta(s.city); if (!crtC.Valido) { ctrl.Valido = crtC.Valido; ctrl.Errore = crtC.Errore + " - Mittente"; } // CONTROLLO PROVINCIA crt crtP = verificaProvincia(s.province); if (!crtP.Valido) { ctrl.Valido = crtP.Valido; ctrl.Errore = crtP.Errore + " - Mittente"; } // CONTROLLO STATO crt crtS = verificaStato(s.state); if (!crtS.Valido) { ctrl.Valido = crtS.Valido; ctrl.Errore = crtS.Errore + " - Mittente"; } return(ctrl); }