//----------------------------TipoDocumento----------------------------
        public tipoDocumento darTipoDocumentoPorCodigo(int codigo)
        {
            tipoDocumento antecedente = null;
            String        urlRelativa = "darTipoDocumento";
            var           url         = $"" + urlGeneral + urlRelativa + "?codigo=" + codigo;
            var           request     = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Accept      = "application/json";

            try
            {
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream strReader = response.GetResponseStream())
                    {
                        if (strReader == null)
                        {
                            return(antecedente);
                        }
                        using (StreamReader objReader = new StreamReader(strReader))
                        {
                            string responseBody = objReader.ReadToEnd();
                            antecedente = JsonConvert.DeserializeObject <tipoDocumento>(responseBody);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex);
            }
            return(antecedente);
        }
Esempio n. 2
0
 protected void btnSincronizar_Click(object sender, EventArgs e)
 {
     try
     {
         List <Int64> Personas = new List <Int64>();
         DocumentacionDemoLocalEntities contextoL = new DocumentacionDemoLocalEntities();
         var resultado = from p in contextoL.vw_consultaCasoDocumentacion.AsNoTracking()
                         where p.regModificado == true
                         select p;
         foreach (var elemento in resultado)
         {
             DocumentacionDemoEntities contextoR = new DocumentacionDemoEntities();
             procesoDocumentacion      registro  = contextoR.procesoDocumentacion.FirstOrDefault(X => X.uniqueIdentifier == elemento.uniqueIdentifier);
             //Informacion del caso
             tipoDocumento TipoDocumento = contextoR.tipoDocumento.FirstOrDefault(X => X.descripcionDocumento == elemento.tipoDocumentoDestinatario);
             genero        Genero        = contextoR.genero.FirstOrDefault(X => X.descripcionGenero == elemento.GeneroDestinatario);
             parentesco    Parentesco    = contextoR.parentesco.FirstOrDefault(X => X.nombreParentesco == elemento.nombreParentesco);
             registro.parentesco          = Parentesco.idPerentesco;
             registro.porcentaje          = elemento.porcentaje;
             registro.usuarioModificacion = elemento.usuarioModificacion;
             registro.fechaModificacion   = elemento.fechaModificacion;
             registro.regModificado       = true;
             //Informacion de la persona
             registro.persona1.primerNombre    = elemento.primerNombreDestinatario;
             registro.persona1.segundoNombre   = elemento.segundoNombreDestinatario;
             registro.persona1.primerApellido  = elemento.primerApellidoDestinatario;
             registro.persona1.segundoApellido = elemento.segundoApellidoDestinatario;
             registro.persona1.tipoDocumento   = TipoDocumento.idTipoDocumento;
             registro.persona1.noDocumento     = elemento.noDocumentoDestinatario;
             registro.persona1.fechaNacimiento = elemento.fechaNacimientoDestinatario;
             registro.persona1.genero          = Genero.idGenero;
             contextoR.SaveChanges();
             var soportesXradicado = from p in contextoL.soporteXRadicado.AsNoTracking()
                                     where p.rad == elemento.rad && p.idPersona == elemento.idPersonaDestinatario
                                     select p;
             if (soportesXradicado != null)
             {
                 foreach (var soporte in soportesXradicado)
                 {
                     soporteXRadicado NvoSoporteRadicado = new soporteXRadicado();
                     NvoSoporteRadicado.idSoporte              = soporte.idSoporte;
                     NvoSoporteRadicado.idPersona              = soporte.idPersona;
                     NvoSoporteRadicado.rad                    = soporte.rad;
                     NvoSoporteRadicado.estadoSoporte          = soporte.estadoSoporte;
                     NvoSoporteRadicado.rutaSoporte            = soporte.rutaSoporte;
                     NvoSoporteRadicado.usuarioCreacionSoporte = soporte.usuarioCreacionSoporte;
                     NvoSoporteRadicado.fechaCreacionSoporte   = soporte.fechaCreacionSoporte;
                     contextoR.soporteXRadicado.Add(NvoSoporteRadicado);
                     contextoR.SaveChanges();
                 }
             }
         }
         foreach (var item in resultado)
         {
             procesoDocumentacion objeto = contextoL.procesoDocumentacion.FirstOrDefault(X => X.uniqueIdentifier == item.uniqueIdentifier);
             eliminaregistros(objeto);
             Personas.Add(objeto.idPersonaDestinatario);
         }
         var personasEliminar = from P in contextoL.persona
                                where Personas.Contains(P.idPersona)
                                select P;
         foreach (var item in personasEliminar)
         {
             persona Persona = contextoL.persona.FirstOrDefault(X => X.idPersona == item.idPersona);
             Script = "delete from persona where idPersona = '" + Persona.idPersona + "'";
             c.ConsultaAUX(Script);
         }
         panelMensajes.CssClass = "alert alert-success";
         Label textoError = new Label();
         textoError.Text = "Se ha realizado la migración del caso al sistema remoto y se ha vaciado la informacion de la base local";
         panelMensajes.Controls.Add(textoError);
         panelMensajes.Visible = true;
         dgvConsultaCasosDocumentacionLocal.DataBind();
     }
     catch (SystemException ex)
     {
         panelMensajes.CssClass = "alert alert-danger";
         Label textoError = new Label();
         textoError.Text = "Error: se ha presentado un error durante la sincronizacion con el sistema Remoto, detalle del error: " + ex.ToString();
         panelMensajes.Controls.Add(textoError);
         panelMensajes.Visible = true;
     }
 }