public async Task <IHttpActionResult> respuestamesajehacienda(string clave) { using (var conexion = new DataModelFE()) { WSRecepcionPOST dato = conexion.WSRecepcionPOST.Find(clave); if (dato.montoTotalFactura > 0) { return(Ok(new WSDomain.WSRespuestaGET(dato))); } else { EmisorReceptorIMEC elEmisor = conexion.EmisorReceptorIMEC.Find(Usuario.USUARIO_TOKEN); string ambiente = ConfigurationManager.AppSettings["ENVIROMENT"].ToString(); OAuth2.OAuth2Config config = conexion.OAuth2Config.Where(x => x.enviroment == ambiente).FirstOrDefault(); config.username = elEmisor.usernameOAuth2; config.password = elEmisor.passwordOAuth2; await OAuth2.OAuth2Config.getTokenWeb(config); string respuestaJSON = await ServicesHacienda.getRecepcion(config.token, clave); if (!string.IsNullOrWhiteSpace(respuestaJSON)) { WSRecepcionGET respuesta = JsonConvert.DeserializeObject <WSRecepcionGET>(respuestaJSON); if (respuesta.respuestaXml != null) { string respuestaXML = EncodeXML.EncondeXML.base64Decode(respuesta.respuestaXml); MensajeHacienda mensajeHacienda = new MensajeHacienda(respuestaXML); dato = conexion.WSRecepcionPOST.Find(clave); dato.mensaje = mensajeHacienda.mensajeDetalle; dato.indEstado = mensajeHacienda.mensaje; dato.fechaModificacion = Date.DateTimeNow(); dato.usuarioModificacion = Usuario.USUARIO_AUTOMATICO; //dato.receptorIdentificacion = mensajeHacienda.receptorNumeroCedula; dato.montoTotalFactura = mensajeHacienda.montoTotalFactura; dato.montoTotalImpuesto = mensajeHacienda.montoTotalImpuesto; conexion.Entry(dato).State = EntityState.Modified; conexion.SaveChanges(); return(Ok(new WSRespuestaGET(dato))); } else { if (respuesta.indEstado.ToLower().Equals("recibido")) { using (var conexionWS = new DataModelFE()) { dato = conexionWS.WSRecepcionPOST.Find(clave); dato.indEstado = 8 /*recibido por hacienda*/; dato.fechaModificacion = Date.DateTimeNow(); dato.usuarioModificacion = Usuario.USUARIO_AUTOMATICO; conexionWS.Entry(dato).State = EntityState.Modified; conexionWS.SaveChanges(); return(Ok(new WSRespuestaGET(dato))); } } } } } } return(NotFound()); }
public async Task <IHttpActionResult> respuestamesajehacienda(string clave) { try { using (var conexion = new DataModelFE()) { WSRecepcionPOST dato = conexion.WSRecepcionPOST.Find(clave); if (dato != null) { if (dato.montoTotalFactura == 0) { return(Ok(new WSRespuestaGET(dato))); } else { string respuestaJSON = await ServicesHacienda.getRecepcion(await this.getToken(), clave); if (!string.IsNullOrWhiteSpace(respuestaJSON)) { WSRecepcionGET respuesta = JsonConvert.DeserializeObject <WSRecepcionGET>(respuestaJSON); if (respuesta.respuestaXml != null) { string respuestaXML = respuesta.respuestaXml; MensajeHacienda mensajeHacienda = new MensajeHacienda(respuestaXML); //dato = conexion.WSRecepcionPOST.Where(x=>x.clave==clave).FirstOrDefault(); dato.mensaje = mensajeHacienda.mensajeDetalle; dato.indEstado = mensajeHacienda.mensaje; dato.fechaModificacion = Date.DateTimeNow(); dato.usuarioModificacion = Usuario.USUARIO_AUTOMATICO; //dato.receptorIdentificacion = mensajeHacienda.receptorNumeroCedula; dato.montoTotalFactura = mensajeHacienda.montoTotalFactura; dato.montoTotalImpuesto = mensajeHacienda.montoTotalImpuesto; conexion.Entry(dato).State = EntityState.Modified; conexion.SaveChanges(); return(Ok(new WSRespuestaGET(dato))); } else { if (respuesta.indEstado.ToLower().Equals("recibido")) { using (var conexionWS = new DataModelFE()) { dato = conexionWS.WSRecepcionPOST.Find(clave); dato.indEstado = 8 /*recibido por hacienda*/; dato.fechaModificacion = Date.DateTimeNow(); dato.usuarioModificacion = Usuario.USUARIO_AUTOMATICO; conexionWS.Entry(dato).State = EntityState.Modified; conexionWS.SaveChanges(); return(Ok(new WSRespuestaGET(dato))); } } } } } } } return(NotFound()); } 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(Ok(fullErrorMessage)); } catch (Exception ex) { return(Ok(ex.Message)); } }