public async Task <bool> ValorizzaConfirm(List <Names> names, Guid guidUser) { ROLServiceSoapClient service = new ROLServiceSoapClient(); service = getNewServiceRol(guidUser); Richiesta[] Richiesta = new Richiesta[names.Count]; int y = 0; foreach (var n in names) { Richiesta r = new Richiesta(); r.GuidUtente = n.guidUser; r.IDRichiesta = n.requestId; Richiesta[y] = r; y++; } Thread.Sleep(15000); var v = await service.ValorizzaAsync(Richiesta); int i = 0; if (v.ValorizzaResult.CEResult.Type != "I") { do { Thread.Sleep(5000); v = await service.ValorizzaAsync(Richiesta); i++; } while (v.ValorizzaResult.CEResult.Type != "I" && i < 50); } if (v.ValorizzaResult.CEResult.Type != "I") { foreach (var n in names) { var nn = _context.Names.SingleOrDefault(a => a.requestId == n.requestId); nn.requestId = null; _context.SaveChanges(); } return(false); } var ServizioEnquiryResponse = v.ValorizzaResult.ServizioEnquiryResponse.ToList(); var conferma = await service.PreConfermaAsync(Richiesta, true); int z = 0; foreach (var s in ServizioEnquiryResponse) { var n = _context.Names.SingleOrDefault(a => a.requestId == s.Richiesta.IDRichiesta); if (s.StatoLavorazione.Descrizione.ToLower() == "prezzato") { var p = new Prices() { price = Convert.ToDecimal(s.Totale.ImportoNetto), vatPrice = Convert.ToDecimal(s.Totale.ImportoIva), totalPrice = Convert.ToDecimal(s.Totale.ImportoTotale) }; if (conferma.PreConfermaResult.DestinatariRaccomandata[z] != null) { n.guidUser = s.Richiesta.GuidUtente; n.orderId = conferma.PreConfermaResult.IdOrdine; n.price = Convert.ToDecimal(s.Totale.ImportoNetto); n.vatPrice = Convert.ToDecimal(s.Totale.ImportoIva); n.totalPrice = Convert.ToDecimal(s.Totale.ImportoTotale); n.currentState = (int)currentState.PresoInCarico; n.codice = conferma.PreConfermaResult.DestinatariRaccomandata[z].NumeroRaccomandata; } else { n.valid = false; n.stato = "Errore nella conferma dell'invio"; } } else { n.valid = false; n.stato = "Errore nella conferma dell'invio"; } _context.SaveChanges(); z++; } return(true); }