protected async void btnEnvioManual_Click(object sender, EventArgs e) { try { if (TipoDocumento.PENDIENTE.ToString().Equals(Session["indEstado"].ToString()) || TipoDocumento.ENVIADO.ToString().Equals(Session["indEstado"].ToString())) { Thread.CurrentThread.CurrentCulture = Utilidades.getCulture(); using (var conexion = new DataModelFE()) { string clave = Session["clave"].ToString(); WSRecepcionPOST dato = conexion.WSRecepcionPOST.Find(clave); string xml = dato.comprobanteXml; DocumentoElectronico documento = (DocumentoElectronico)EncodeXML.XMLUtils.getObjetcFromXML(xml); documento.verificaDatosParaXML(); EmisorReceptorIMEC elEmisor = ((EmisorReceptorIMEC)Session["elEmisor"]); string responsePost = await Services.enviarDocumentoElectronico(false, documento, elEmisor, dato.tipoDocumento, Session["usuario"].ToString()); string correoElectronico = XMLUtils.buscarValorEtiquetaXML("Receptor", "CorreoElectronico", xml); if (responsePost.Equals("Success")) { this.alertMessages.Attributes["class"] = "alert alert-info"; this.alertMessages.InnerText = String.Format("Documento #{0} enviada.", dato.numeroConsecutivo); if (!string.IsNullOrWhiteSpace(correoElectronico)) { Utilidades.sendMail(Session["emisor"].ToString(), correoElectronico, string.Format("{0} - {1}", dato.numeroConsecutivo, dato.receptor.nombre), Utilidades.mensageGenerico(), "Documento Electrónico", xml, dato.numeroConsecutivo, dato.clave, null); } } else if (responsePost.Equals("Error")) { this.alertMessages.Attributes["class"] = "alert alert-danger"; this.alertMessages.InnerText = String.Format("Documento #{0} con errores.", dato.numeroConsecutivo); } else { this.alertMessages.Attributes["class"] = "alert alert-warning"; this.alertMessages.InnerText = String.Format("Documento #{0} pendiente de envío", dato.numeroConsecutivo); } } } else { this.alertMessages.Attributes["class"] = "alert alert-danger"; this.alertMessages.InnerText = String.Format("Documento eléctronico no se encuentra PENDIENTE"); } } catch (Exception ex) { this.alertMessages.InnerText = Utilidades.validarExepcionSQL(ex); } }
public async Task <HttpResponseMessage> recepcionmesajehacienda() { string responsePost = ""; try { Thread.CurrentThread.CurrentCulture = Utilidades.getCulture(); string xml = await Request.Content.ReadAsStringAsync(); DocumentoElectronico documento = (DocumentoElectronico)EncodeXML.XMLUtils.getObjetcFromXML(xml); documento.verificaDatosParaXML(); EmisorReceptorIMEC elEmisor = null; using (var conexion = new DataModelFE()) { long id = long.Parse(documento.emisor.identificacion.numero); elEmisor = conexion.EmisorReceptorIMEC.Find(id.ToString()); if (elEmisor == null) { //return "Emisor no registrado!!!"; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emisor no registrado!!!")); //return Ok("Emisor no registrado!!!"); } } responsePost = await ServicesHacienda.enviarDocumentoElectronico(false, documento, elEmisor, documento.tipoDocumento, Usuario.USUARIO_AUTOMATICO); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Throw a new DbEntityValidationException with the improved exception message. //return fullErrorMessage; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, fullErrorMessage)); //return Ok(fullErrorMessage); } catch (Exception ex) { //return ex.Message; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); //return Ok(ex.Message); } //return responsePost; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, responsePost)); //return Ok(responsePost); }
public async Task <HttpResponseMessage> recepcionmesajehacienda() { string responsePost = ""; try { Thread.CurrentThread.CurrentCulture = Utilidades.getCulture(); string xml = await Request.Content.ReadAsStringAsync(); DocumentoElectronico documento = (DocumentoElectronico)EncodeXML.XMLUtils.getObjetcFromXML(xml); documento.verificaDatosParaXML(); EmisorReceptorIMEC elEmisor = null; using (var conexion = new DataModelFE()) { long idE = long.Parse(documento.emisor.identificacion.numero); elEmisor = conexion.EmisorReceptorIMEC.Find(idE.ToString()); if (elEmisor == null) { //return "Emisor no registrado!!!"; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Emisor no registrado!!!")); //return Ok("Emisor no registrado!!!"); } else// si el xml es de un emisor valido, verifica si existe el receptor y si no lo crea { string tipo = ""; string idReceptor = ""; if (!string.IsNullOrWhiteSpace(documento.receptor.identificacionExtranjero)) { tipo = "99"; idReceptor = documento.receptor.identificacionExtranjero; } else { //elimina ceros a la izquierda long idR = long.Parse(documento.receptor.identificacion.numero); tipo = documento.receptor.identificacion.tipo; idReceptor = idR.ToString(); } EmisorReceptorIMEC elReceptor = conexion.EmisorReceptorIMEC.Find(idReceptor); if (elReceptor == null) { // crea un cliente para que se muestre el emisor elReceptor = new EmisorReceptorIMEC(); elReceptor.identificacion = idReceptor; elReceptor.identificacionTipo = tipo; elReceptor.correoElectronico = documento.receptor.correoElectronico; if (documento.receptor.telefono != null) { elReceptor.telefonoCodigoPais = documento.receptor.telefono.codigoPais; elReceptor.telefono = documento.receptor.telefono.numTelefono; } elReceptor.nombre = documento.receptor.nombre; elReceptor.nombreComercial = documento.receptor.nombreComercial; conexion.EmisorReceptorIMEC.Add(elReceptor); conexion.SaveChanges(); } } } responsePost = await ServicesHacienda.enviarDocumentoElectronico(false, documento, elEmisor, documento.tipoDocumento, Usuario.USUARIO_AUTOMATICO); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Throw a new DbEntityValidationException with the improved exception message. //return fullErrorMessage; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, fullErrorMessage)); //return Ok(fullErrorMessage); } catch (Exception ex) { //return ex.Message; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex.Message)); //return Ok(ex.Message); } //return responsePost; return(Request.CreateErrorResponse(HttpStatusCode.NotFound, responsePost)); //return Ok(responsePost); }