示例#1
0
        //
        // GET: /Home/
        public ActionResult Index()
        {
            string respuestaCaso = string.Empty;

            //string datosJSON = string.Empty;
            try
            {
                ////Obtener ultimo parametro de la url de la página que será el link
                string hola = "https://10.2.0.230/CreacionProveedor/PMRE45LNMVZG6ZDFINQXG3ZCHIRCANJTEARCYITJMRBWC43FEI5CEIBVGMQCELBCMR2XEYLDNFXW4TDJNZVSEORCEAYTAIBCFQRGMZLDNBQUOZLOMVZGCY3JN5XCEORCEBKHKZJAJ5RXIIBRGUQDAMB2GAYDUMBQEBKVIQZNGQQDEMBRHEQCELBCNFSFG33MNFRWS5DVMQRDUIRAGUZSAIT5";
                //string[] url = Request.Url.Query.Split('/');
                string[] url            = hola.Split('/');
                string   linkEncriptado = url.Last();
                ////Descifrar link

                Base32.Net4.Encoder enco = new Base32.Net4.Encoder();
                string decodificado      = enco.DecodeFromBase32String(linkEncriptado);
                //datosJSON = JsonConvert.SerializeObject(decodificado);
                var datosJSON  = JObject.Parse(decodificado);
                var numeroCaso = datosJSON["NumerodeCaso"].ToString();
                if (numeroCaso != null && numeroCaso != "")
                {
                    numeroCaso = numeroCaso.Trim();

                    System.Web.HttpContext.Current.Session["NroCaso"] = numeroCaso;

                    //Escribir log CSV
                    UtilController.EscribirLog("Numero de caso obtenido", "Index", numeroCaso);
                    //Fin CSV

                    ////Obtener informacion del idCase, numero de caso (y id Entidad de la coleccion en caso de ser corrección)

                    // XML Búsqueda
                    string xmlGetEntities = @"
                    <BizAgiWSParam>
                        <EntityData>
                            <EntityName>M_ProcesoCreacionDeProve</EntityName>
                            <Filters>
                                <![CDATA[NumerodeCaso = '" + numeroCaso + @"']]>
                            </Filters>
                        </EntityData>
                    </BizAgiWSParam>";

                    //Escribir log CSV
                    UtilController.EscribirLog("Consultar numero de caso", "Index", xmlGetEntities);
                    //Fin CSV

                    // Abrir conexión a servicio web
                    EntityManager.EntityManagerSOASoapClient servicioQuery = new EntityManager.EntityManagerSOASoapClient();

                    respuestaCaso = servicioQuery.getEntitiesAsString(xmlGetEntities);
                    respuestaCaso = respuestaCaso.Replace("\n", "");
                    respuestaCaso = respuestaCaso.Replace("\t", "");
                    respuestaCaso = respuestaCaso.Replace("\r", "");

                    //Escribir log CSV
                    UtilController.EscribirLog("respuestaCaso", "Index", respuestaCaso);
                    //Fin CSV

                    //Transformar respuesta STRING de Bizagi a XML para poder recorrer los nodos
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(respuestaCaso);

                    var      idEntidadSolicitud  = "";
                    var      fechaGeneracionLink = "";
                    var      duracionLink        = "";
                    DateTime fechaActual         = DateTime.Today;
                    string   completadoWeb       = "";
                    string   idioma = "";

                    //Guardar "fecha generacion link", "duracion de link", idEntidadSolicitud, numeroCaso y declarar la fecha actual
                    if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/Fechageneracionlink").InnerText != null)
                    {
                        fechaGeneracionLink = doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/Fechageneracionlink").InnerText;
                    }
                    if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/Diasduracionlink").InnerText != null)
                    {
                        duracionLink = doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/Diasduracionlink").InnerText;
                    }
                    if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/CompletadoWeb").InnerText != null)
                    {
                        completadoWeb = doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/CompletadoWeb").InnerText;
                    }
                    if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/SolicitudCreaciondeProve.Idioma.Idioma").InnerText != null)
                    {
                        idioma = doc.SelectSingleNode("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/SolicitudCreaciondeProve.Idioma.Idioma").InnerText;
                    }
                    foreach (XmlNode item in doc.SelectNodes("/BizAgiWSResponse/Entities/M_ProcesoCreacionDeProve/SolicitudCreaciondeProve"))
                    {
                        // Obtener campos
                        idEntidadSolicitud = item.Attributes["key"].Value;
                        Convert.ToInt32(idEntidadSolicitud);
                    }

                    //Restar la fecha actual con la fecha generacion de link y los dias que de resultado, comparar con duracion de link, asi determinar si es válido o no.
                    TimeSpan resultadoFechas = fechaActual.Subtract(Convert.ToDateTime(fechaGeneracionLink));
                    int      diasDiferencia  = resultadoFechas.Days;
                    if (completadoWeb != "True")
                    {
                        //Paginas español. CREAR CONDICION EVALUANDO CAMPO DE IDIOMA ELEGIDO
                        if (idioma == "Español")
                        {
                            if (Convert.ToInt32(duracionLink) >= diasDiferencia)
                            {
                                //mostrar index
                                System.Web.HttpContext.Current.Session["UrlValida"] = "1";
                                ViewData["UrlValida"] = System.Web.HttpContext.Current.Session["UrlValida"];
                            }
                            else
                            {
                                throw new Exception("Página caducada");
                            }
                        }
                        else if (idioma == "Ingles")
                        {
                            if (Convert.ToInt32(duracionLink) >= diasDiferencia)
                            {
                                //mostrar index
                                System.Web.HttpContext.Current.Session["UrlValida"] = "1";
                                ViewData["UrlValida"] = System.Web.HttpContext.Current.Session["UrlValida"];
                            }
                            else
                            {
                                throw new Exception("Página caducada");
                            }
                        }
                        //Paginas ingles
                    }
                    else
                    {
                        throw new Exception("Página ya fue completada. Se redirecciona a página caducada");
                    }

                    //Cargar tabla de tipo de proveedor
                    string listaTipoProveedor = UtilController.ListarParametrica("P_Moneda", "Moneda");
                    ViewData["txtMoneda"] = listaTipoProveedor;
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Caducado", "Home"));
            }
            //ViewData["UrlValida"] = "1";
            return(View());
        }
示例#2
0
        public string ActualizarCasoArchivos(FormCollection collection, IEnumerable <HttpPostedFileBase> files)
        {
            string IDUsuario         = "";
            string idRegistro        = "";
            string respuestaBizagi   = "";
            string archivoConvertido = "";

            try
            {
                if (System.Web.HttpContext.Current.Session["NroCasoTemp"] != null)
                {
                    idRegistro = System.Web.HttpContext.Current.Session["IdRegistro"].ToString();
                    IDUsuario  = System.Web.HttpContext.Current.Session["IDUsuario"].ToString();
                    Convert.ToInt32(IDUsuario);
                    ViewData["IDUsuario"] = IDUsuario;
                    int numCaso     = Convert.ToInt32(System.Web.HttpContext.Current.Session["NroCasoTemp"]);
                    var archivoSoli = collection["txtArchivoContratista"];

                    // Conversión de archivos
                    string archivosBase64    = "";
                    string archivosNombres   = "";
                    string archivosRespaldos = "";
                    foreach (string upload in Request.Files)
                    {
                        if (Request.Files[upload].FileName != "")
                        {
                            //string path = AppDomain.CurrentDomain.BaseDirectory + "./";
                            string path     = Path.GetTempPath();
                            string filename = Request.Files[upload].FileName;
                            Request.Files[upload].SaveAs(Path.Combine(path, filename));
                            archivoConvertido = ConversorBase64.convertirABase64(path + filename);
                            if (upload != null)
                            {
                                archivosBase64     = archivoConvertido;
                                archivosNombres    = archivoConvertido;
                                archivosRespaldos += @"<File fileName=""" + filename + @""">" + archivoConvertido + @"</File>";
                                //archivosRespaldos += @"<File fileName='" + filename + @"'>" + archivoConvertido + @"</File>";
                            }
                        }
                    }

                    //LipigasEntityManagerSoa.EntityManagerSOASoapClient servicioQuery = new LipigasEntityManagerSoa.EntityManagerSOASoapClient();
                    //DemoLipiEntity.EntityManagerSOASoapClient servicioQuery = new DemoLipiEntity.EntityManagerSOASoapClient();
                    DesEntity.EntityManagerSOASoapClient servicioQuery = new DesEntity.EntityManagerSOASoapClient();

                    //Escribir log CSV
                    UtilController.EscribirLog("Caso a actualizar", "ActualizarCasoArchivos", Convert.ToString(numCaso));
                    //Fin CSV

                    //XML PARA ACTUALIZAR VALORES DEL CASO
                    string queryActualizarCaso = @"<BizAgiWSParam>
                                                    <Entities idCase='" + numCaso + @"'>
                                                        <OrdendeTrabajoMedidor key='" + idRegistro + @"'>
                                                            <RespaldoAtencion>" + archivosRespaldos + @"</RespaldoAtencion>
                                                        </OrdendeTrabajoMedidor>
                                                    </Entities>
                                               </BizAgiWSParam>";

                    System.Web.HttpContext.Current.Session["NroCasoTemp"] = null;

                    //Escribir log CSV
                    queryActualizarCaso = queryActualizarCaso.Replace("\n", "");
                    queryActualizarCaso = queryActualizarCaso.Replace("\t", "");
                    queryActualizarCaso = queryActualizarCaso.Replace("\r", "");
                    UtilController.EscribirLog("Datos a actualizar", "ActualizarCasoArchivos", queryActualizarCaso);
                    //Fin CSV

                    respuestaBizagi = servicioQuery.saveEntityAsString(queryActualizarCaso);
                    respuestaBizagi = respuestaBizagi.Replace("\n", "");
                    respuestaBizagi = respuestaBizagi.Replace("\t", "");
                    respuestaBizagi = respuestaBizagi.Replace("\r", "");

                    //Escribir log CSV
                    UtilController.EscribirLog("Respuesta", "ActualizarCasoArchivos", respuestaBizagi);
                    //Fin CSV
                }
            }
            catch (Exception ex)
            {
                //Escribir log CSV
                UtilController.EscribirLog("ERROR", "ActualizarCasoArchivos", ex.Message);
                //Fin CSV
            }

            return(respuestaBizagi);
        }
示例#3
0
        public string ActualizarCaso(FormCollection collection, IEnumerable <HttpPostedFileBase> files)
        {
            string   respuestaBizagi = string.Empty;
            DateTime fechaDeVisita   = DateTime.MinValue;
            string   IDUsuario       = "";
            string   idRegistro      = "";

            try
            {
                IDUsuario = System.Web.HttpContext.Current.Session["IDUsuario"].ToString();
                Convert.ToInt32(IDUsuario);
                ViewData["IDUsuario"] = IDUsuario;
                int numCaso          = Convert.ToInt32(collection["txtNumCaso"]);
                var fechaVisita      = collection["txtFechaDeVisita"];
                var archivoSoli      = collection["txtArchivoContratista"];
                var comentarioCierre = collection["txtComentarioCierre"];

                fechaDeVisita = Convert.ToDateTime(fechaVisita);
                fechaDeVisita.ToString("yyyy-MM-dd HH':'mm':'ss");

                // Conversión de archivos
                string archivosBase64    = "";
                string archivosNombres   = "";
                string archivosRespaldos = "";
                foreach (string upload in Request.Files)
                {
                    if (Request.Files[upload].FileName != "")
                    {
                        //string path = AppDomain.CurrentDomain.BaseDirectory + "./";
                        string path     = Path.GetTempPath();
                        string filename = Request.Files[upload].FileName;
                        Request.Files[upload].SaveAs(Path.Combine(path, filename));
                        string archivoConvertido = ConversorBase64.convertirABase64(path + filename);
                        if (upload != null)
                        {
                            archivosBase64     = archivoConvertido;
                            archivosNombres    = archivoConvertido;
                            archivosRespaldos += @"<File fileName='" + filename + @"'>" + archivoConvertido + @"</File>";
                        }
                    }
                }

                //LipigasEntityManagerSoa.EntityManagerSOASoapClient servicioQuery = new LipigasEntityManagerSoa.EntityManagerSOASoapClient();
                //DemoLipiEntity.EntityManagerSOASoapClient servicioQuery = new DemoLipiEntity.EntityManagerSOASoapClient();
                DesEntity.EntityManagerSOASoapClient servicioQuery = new DesEntity.EntityManagerSOASoapClient();

                //Escribir log CSV
                UtilController.EscribirLog("Caso a actualizar", "ActualizarCaso", Convert.ToString(numCaso));
                //Fin CSV

                //XML PARA ACTUALIZAR VALORES DEL CASO
                string queryActualizarCaso = @"<BizAgiWSParam>
                                                    <Entities>
                                                        <OrdendeTrabajoMedidor businessKey=""NroCaso='" + numCaso + @"'"">
                                                            <ComentarioCierreSolicitud>" + comentarioCierre + @"</ComentarioCierreSolicitud>
                                                            <FechadeVisita>" + fechaVisita + @"</FechadeVisita>
                                                        </OrdendeTrabajoMedidor>
                                                    </Entities>
                                               </BizAgiWSParam>";

                //Escribir log CSV
                UtilController.EscribirLog("Datos a actualizar", "ActualizarCaso", queryActualizarCaso);
                //Fin CSV

                respuestaBizagi = servicioQuery.saveEntityAsString(queryActualizarCaso);
                respuestaBizagi = respuestaBizagi.Replace("\n", "");
                respuestaBizagi = respuestaBizagi.Replace("\t", "");
                respuestaBizagi = respuestaBizagi.Replace("\r", "");

                //Obtener id del registro actualizado para ocuparlo como filtro en el metodo para actualizar archivo
                //Transformar respuesta STRING de Bizagi a XML para poder recorrer los nodos
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(respuestaBizagi);
                XmlNodeList rows = doc.GetElementsByTagName("OrdendeTrabajoMedidor");

                if (rows != null)
                {
                    foreach (XmlNode row in rows)
                    {
                        if (doc.GetElementsByTagName("OrdendeTrabajoMedidor")[0] != null)
                        {
                            idRegistro = doc.GetElementsByTagName("OrdendeTrabajoMedidor")[0].InnerText;
                        }
                    }
                }

                //Escribir log CSV
                UtilController.EscribirLog("Respuesta", "ActualizarCaso", respuestaBizagi);
                //Fin CSV
                System.Web.HttpContext.Current.Session["NroCasoTemp"] = numCaso;
                System.Web.HttpContext.Current.Session["IdRegistro"]  = idRegistro;
            }
            catch (Exception ex)
            {
                //Escribir log CSV
                UtilController.EscribirLog("ERROR", "ActualizarCaso", ex.Message);
                //Fin CSV
            }

            return(respuestaBizagi);
        }
示例#4
0
        public string ObtenerCaso(int id)
        {
            string respuestaBizagi = string.Empty;

            try
            {
                int numCasoXML = id;
                //LipigasEntityManagerSoa.EntityManagerSOASoapClient servicioQuery = new LipigasEntityManagerSoa.EntityManagerSOASoapClient();
                //DemoLipiEntity.EntityManagerSOASoapClient servicioQuery = new DemoLipiEntity.EntityManagerSOASoapClient();
                DesEntity.EntityManagerSOASoapClient servicioQuery = new DesEntity.EntityManagerSOASoapClient();

                //Escribir log CSV
                UtilController.EscribirLog("Caso a trabajar", "ObtenerCaso", Convert.ToString(numCasoXML));
                //Fin CSV

                //Crear XML para obtener la información del caso seleccionado para trabajar

                string queryObtenerCaso = @"
                <BizAgiWSParam>
                    <CaseInfo>
                        <IdCase>" + id + @"</IdCase>
                    </CaseInfo>
                    <XPaths>
                        <XPath XPath=""OrdendeTrabajoMedidor.FechaSolicitud""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.SolicitanteOTMedidor.NombreSolicitante""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.EjecutivoOficina.CorreoElectronico""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.EjecutivoOficina.Nombre""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.NumeroTicketCRM""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.SinCuentaContrato""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.CuentaContrato""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Nombre""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.SolicitanteOTMedidor""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.NumeroSerieMedidor""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Ciudad""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Direccion""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.SeleccionarCliente""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Contacto.NombreContacto""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Contacto.CorreoElectronico""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Contacto.TelefonoFijo""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Contacto.Celular""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Region.Nombre""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Comunas.Comuna""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.ContratistasOTMedidor.Nombre""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.ContratistasOTMedidor.CorreoElectronico""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.MotivoOT.Motivo""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.SubMotivoOT.Submotivo""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.ComentarioSolicitud""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.Archivo""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.FechadeVisita""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.ComentarioCierreSolicitud""/>
                        <XPath XPath=""OrdendeTrabajoMedidor.RespaldoAtencion""/>
                    </XPaths>
                    </BizAgiWSParam>";

                //Escribir log CSV
                UtilController.EscribirLog("Campos solicitados", "ObtenerCaso", queryObtenerCaso);
                //Fin CSV

                respuestaBizagi = servicioQuery.getCaseDataUsingXPathsAsString(queryObtenerCaso);
                respuestaBizagi = respuestaBizagi.Replace("\n", "");
                respuestaBizagi = respuestaBizagi.Replace("\t", "");
                respuestaBizagi = respuestaBizagi.Replace("\r", "");

                //Escribir log CSV
                UtilController.EscribirLog("Respuesta", "ObtenerCaso", respuestaBizagi);
                //Fin CSV
            }
            catch (Exception ex)
            {
                //Escribir log CSV
                UtilController.EscribirLog("ERROR", "ObtenerCaso", ex.Message);
                //Fin CSV
            }
            return(respuestaBizagi);
        }
示例#5
0
        public ActionResult Login(FormCollection collection, int?estado)
        {
            string         datosJSON      = string.Empty;
            string         respuestaCasos = "";
            string         idUsuario      = "";
            string         txtVacio       = collection["txtVacio"];
            FormCollection nulo           = new FormCollection();

            try
            {
                //Obtener valores ingresados en formulario de login
                string txtCorreo = collection["txtCorreo"];
                string txtPass   = collection["txtPass"];

                if (txtCorreo != null)
                {
                    txtCorreo.Trim();
                }
                if (txtPass != null)
                {
                    txtPass.Trim();
                }

                //Escribir log CSV
                UtilController.EscribirLog("Credenciales ingresadas", "Login", "Correo: " + txtCorreo + ", Clave: " + txtPass);
                //Fin CSV

                //Consultar a tabla si correo y password coinciden
                string queryLogin = @"<BizAgiWSParam>
	                                    <EntityData>
		                                    <EntityName>ContratistasOTMedidor</EntityName>
		                                    <Filters>
			                                    <![CDATA[CorreoElectronico = '"             + txtCorreo + @"' AND Pass = '******']]>
		                                    </Filters>
	                                    </EntityData>
                                    </BizAgiWSParam>";

                //Escribir log CSV
                UtilController.EscribirLog("Consultar credenciales", "Login", queryLogin);
                //Fin CSV

                //LipigasEntityManagerSoa.EntityManagerSOASoapClient servicioQuery = new LipigasEntityManagerSoa.EntityManagerSOASoapClient();
                //DemoLipiEntity.EntityManagerSOASoapClient servicioQuery = new DemoLipiEntity.EntityManagerSOASoapClient();
                DesEntity.EntityManagerSOASoapClient servicioQuery = new DesEntity.EntityManagerSOASoapClient();

                respuestaCasos = servicioQuery.getEntitiesAsString(queryLogin);
                respuestaCasos = respuestaCasos.Replace("\n", "");
                respuestaCasos = respuestaCasos.Replace("\t", "");
                respuestaCasos = respuestaCasos.Replace("\r", "");

                //Escribir log CSV
                UtilController.EscribirLog("Respuesta", "Login", respuestaCasos);
                //Fin CSV

                //Transformar respuesta STRING de Bizagi a XML para poder recorrer los nodos
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(respuestaCasos);

                string correo   = "";
                string password = "";
                //Obtener correo y pass de respuesta
                if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/ContratistasOTMedidor/CorreoElectronico").InnerText != null)
                {
                    correo = doc.SelectSingleNode("/BizAgiWSResponse/Entities/ContratistasOTMedidor/CorreoElectronico").InnerText;
                }
                if (doc.SelectSingleNode("/BizAgiWSResponse/Entities/ContratistasOTMedidor/Pass").InnerText != null)
                {
                    password = doc.SelectSingleNode("/BizAgiWSResponse/Entities/ContratistasOTMedidor/Pass").InnerText;
                }

                //Escribir log CSV
                UtilController.EscribirLog("Credenciales rescatadas", "Login", "Correo: " + correo + ", Clave: " + password);
                //Fin CSV

                if (txtCorreo == correo && txtPass == password)
                {
                    // Recorrer los resultados
                    foreach (XmlNode item in doc.SelectNodes("/BizAgiWSResponse/Entities/ContratistasOTMedidor"))
                    {
                        // Obtener campos
                        idUsuario = item.Attributes["key"].Value;
                        Convert.ToInt32(idUsuario);
                    }
                    //Url.Action("ListarCasos", "CasosPendientes", new { collection = txtVacio, IDUsuario = idUsuario });
                }
            }
            catch (Exception ex)
            {
                //Escribir log CSV
                UtilController.EscribirLog("ERROR", "Login", ex.Message);
                //Fin CSV

                return(RedirectToAction("Login", "Home", new { estado = 0 }));
            }

            //return Index(Convert.ToInt32(idUsuario), 1);
            return(RedirectToAction("Index", "Home", new { IDUsuario = idUsuario, estado = 1 }));
        }
示例#6
0
        public string CasosPendientes(FormCollection collection)
        {
            string datosJSON = string.Empty;
            //string txtVacio = collection["txtVacio"];
            string IDUsuario = "";

            try
            {
                IDUsuario = System.Web.HttpContext.Current.Session["IDUsuario"].ToString();
                int UsuarioLogueado = Convert.ToInt32(IDUsuario);
                ViewData["IDUsuario"] = UsuarioLogueado;
                //string IDUsuario = System.Web.HttpContext.Current.Session["IDUsuario"].ToString();
                //if (estado == 1)
                //    ViewData["estado"] = "1";
                //else if (estado == 0)
                //{
                //    ViewData["estado"] = "0";
                //}



                #region Agregar filtros y buscar
                // Variables
                string txtFechaDesde      = collection["txtFechaDesde"];
                string txtFechaHasta      = collection["txtFechaHasta"];
                string txtNroCaso         = collection["txtNroCaso"];
                string txtMotivoSelect    = collection["txtMotivoSelect"];
                string txtSubMotivoSelect = collection["txtSubMotivoSelect"];

                // Fecha inicio
                DateTime fechaInicio = DateTime.MinValue;
                if (txtFechaDesde != string.Empty)
                {
                    DateTime.TryParse(collection["txtFechaDesde"], out fechaInicio);
                }
                //fechaInicio = DateTime.ParseExact(txtFechaDesde, "yyyy-MM-dd", CultureInfo.InvariantCulture);

                // Fecha término
                DateTime fechaTermino = DateTime.MinValue;
                if (txtFechaHasta != string.Empty)
                {
                    DateTime.TryParse(collection["txtFechaHasta"], out fechaTermino);
                }
                //fechaTermino = DateTime.ParseExact(txtFechaHasta, "yyyy-MM-dd", CultureInfo.InvariantCulture);

                //// Número caso
                //int? numCaso = null;
                //if (Convert.ToInt32(txtNroCaso) != 0)
                //    numCaso = int.Parse(txtNroCaso);

                // NumCaso
                int  caso;
                int? numeroCaso;
                bool conversionOK = Int32.TryParse(txtNroCaso, out caso);
                if (conversionOK)
                {
                    numeroCaso = caso;
                }
                else
                {
                    numeroCaso = null;
                }

                // Motivo
                int?motivo = null;
                if (Convert.ToInt32(txtMotivoSelect) != 0)
                {
                    motivo = int.Parse(txtMotivoSelect);
                }

                // Sub Motivo
                int?subMotivo = null;
                if (Convert.ToInt32(txtSubMotivoSelect) != 0)
                {
                    subMotivo = int.Parse(txtSubMotivoSelect);
                }



                #endregion

                #region Queries

                //LipigasQuerySoa.QueryFormSOASoapClient servicioQuery = new LipigasQuerySoa.QueryFormSOASoapClient();
                //DemoLipiQuery.QueryFormSOASoapClient servicioQuery = new DemoLipiQuery.QueryFormSOASoapClient();
                DesQuery.QueryFormSOASoapClient servicioQuery = new DesQuery.QueryFormSOASoapClient();

                int    cantidadCasos  = 20;
                string respuestaCasos = "";

                //Crear XML de consulta de casos (id de proceso 26 = OrdendeTrabajoMedidor)
                string queryCasos = @"
                <BizAgiWSParam>
	              <userName>admon</userName>
	              <domain>domain</domain>
                  <QueryParams>
                      <Internals>
                          <Internal Name='ProcessState' Include='true'>Running</Internal>
                          <Internal Name='idWfClass' Include='true'>26</Internal>
                      </Internals>
                      <XPaths>
                        <XPath Path= 'OrdendeTrabajoMedidor.ContratistasOTMedidor' Include='true'>" + UsuarioLogueado + "</XPath>";//ESTA LINEA CORRESPONDE AL FILTRO POR USUARIO
                if (Convert.ToInt32(txtMotivoSelect) != 0)
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.MotivoOT.Cod' Include='true'>" + motivo + "</XPath>";
                }
                else
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.MotivoOT.Motivo' Include='true'></XPath>";
                }
                if (Convert.ToInt32(txtSubMotivoSelect) != 0)
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.SubMotivoOT.Cod' Include='true'>" + subMotivo + "</XPath>";
                }
                else
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.SubMotivoOT.SubMotivo' Include='true'></XPath>";
                }
                if (numeroCaso != 0)
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.NroCaso' Include='true'>" + numeroCaso + "</XPath>";
                }
                else
                {
                    queryCasos += @"<XPath Path='OrdendeTrabajoMedidor.NroCaso' Include='true'></XPath>";
                }
                queryCasos += @"                    
                          <XPath Path='OrdendeTrabajoMedidor.Fechaasignacion' Include='true'>";
                if (fechaInicio != DateTime.MinValue)
                {
                    queryCasos += @"<From>" + fechaInicio.Day + '/' + fechaInicio.Month + '/' + fechaInicio.Year + "</From>";
                }
                else
                {
                    queryCasos += @"<From>01/01/1900</From>";
                }
                if (fechaTermino != DateTime.MinValue)
                {
                    queryCasos += @"<To>" + fechaTermino.Day + '/' + fechaTermino.Month + '/' + fechaTermino.Year + "</To>";
                }
                else
                {
                }
                queryCasos += @"        
                          </XPath>
                      </XPaths>
                  </QueryParams>
                  <Parameters>
                      <Parameter Name ='pag'>1</Parameter>
                       <Parameter Name='PageSize'>" + cantidadCasos + @"</Parameter>
                    </Parameters>
                </BizAgiWSParam>";

                //Escribir log CSV
                UtilController.EscribirLog("Listar casos pendientes", "CasosPendientes", queryCasos);
                //Fin CSV

                respuestaCasos = servicioQuery.QueryCasesAsString(queryCasos);
                respuestaCasos = respuestaCasos.Replace("\n", "");
                respuestaCasos = respuestaCasos.Replace("\t", "");
                respuestaCasos = respuestaCasos.Replace("\r", "");

                //Escribir log CSV
                UtilController.EscribirLog("Respuesta", "CasosPendientes", respuestaCasos);
                //Fin CSV

                //Transformar respuesta STRING de Bizagi a XML para poder recorrer los nodos
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(respuestaCasos);
                XmlNodeList rows = doc.GetElementsByTagName("Row");

                #endregion

                //#region Crear JSON
                List <List <string> > registros = new List <List <string> >();
                if (rows != null)
                {
                    foreach (XmlNode row in rows)
                    {
                        List <string> fila   = new List <string>();
                        bool          valido = false;
                        //OBTENER NUMERO DE CASO
                        //var numCaso = "";
                        //if (row.SelectNodes("Column[@Name='IDCASE']")[0] != null && row.SelectNodes("Column[@Name='ORDENDETRAB_FECHASOLICITUD']")[0].InnerText != string.Empty)
                        //{
                        //    numCaso = row.SelectNodes("Column[@Name='IDCASE']")[0].InnerText;
                        //    if (txtNroCaso == string.Empty)
                        //    {
                        //        valido = true;
                        //        fila.Add(numCaso);
                        //    }
                        //    else if (txtNroCaso != string.Empty && txtNroCaso == numCaso)
                        //    {
                        //        valido = true;
                        //        fila.Add(numCaso);
                        //    }
                        //}
                        var numCasoXML = "";
                        if (row.SelectNodes("Column[@Name='ORDENDETRABAJOMEDI_NROCASO']")[0] != null && row.SelectNodes("Column[@Name='ORDENDETRABAJOMEDI_NROCASO']")[0].InnerText != string.Empty)
                        {
                            numCasoXML = row.SelectNodes("Column[@Name='ORDENDETRABAJOMEDI_NROCASO']")[0].InnerText;
                            valido     = true;
                            fila.Add(numCasoXML);
                        }

                        ////OBTENER ESTADO DEL CASO
                        //if (row.SelectNodes("Column[@Name='IDCASESTATE']")[0] != null)
                        //{
                        //    var estadoCaso = row.SelectNodes("Column[@Name='IDCASESTATE']")[0].InnerText;
                        //    var estadoTexto = "";
                        //    if (Convert.ToUInt32(estadoCaso) == 2)
                        //    {
                        //        estadoTexto = "En proceso";
                        //    }
                        //    if (Convert.ToInt32(estadoCaso) == 5)
                        //    {
                        //        estadoTexto = "Completado";
                        //    }
                        //    fila.Add(estadoTexto);
                        //}

                        //OBTENER FECHA ASIGNACION
                        if (row.SelectNodes("Column[@Name='ORDENDETRA_FECHAASIGNACION']")[0] != null && row.SelectNodes("Column[@Name='ORDENDETRA_FECHAASIGNACION']")[0].InnerText != string.Empty)
                        {
                            var      fechaAsignacion = row.SelectNodes("Column[@Name='ORDENDETRA_FECHAASIGNACION']")[0].InnerText;
                            DateTime fecha           = Convert.ToDateTime(fechaAsignacion);
                            var      fechaFinal      = fecha.ToString("dd-MM-yyyy");
                            fila.Add(fechaFinal);
                        }

                        //OBTENER MOTIVO OT MEDIDOR
                        if (row.SelectNodes("Column[@Name='MOTIVOOT_MOTIVO']")[0] != null && row.SelectNodes("Column[@Name='MOTIVOOT_MOTIVO']")[0].InnerText != string.Empty)
                        {
                            var motivoOT = row.SelectNodes("Column[@Name='MOTIVOOT_MOTIVO']")[0].InnerText;
                            fila.Add(motivoOT);
                        }
                        //OBTENER MOTIVO OT MEDIDOR FILTRADO POR CODIGO
                        if (row.SelectNodes("Column[@Name='MOTIVOOT_COD']")[0] != null && row.SelectNodes("Column[@Name='MOTIVOOT_COD']")[0].InnerText != string.Empty)
                        {
                            string motivoFiltrado = UtilController.ObtenerAtributoParametricaByCod("MotivoOT", "Cod", row.SelectNodes("Column[@Name='MOTIVOOT_COD']")[0].InnerText, "Motivo");
                            fila.Add(motivoFiltrado);
                        }

                        //OBTENER SUB MOTIVO OT MEDIDOR
                        if (row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_SUBMOTIVO']")[0] != null && row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_SUBMOTIVO']")[0].InnerText != string.Empty)
                        {
                            var subMotivoOT = row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_SUBMOTIVO']")[0].InnerText;
                            fila.Add(subMotivoOT);
                        }

                        //OBTENER SUB MOTIVO OT MEDIDOR POR CODIGO
                        if (row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_COD']")[0] != null && row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_COD']")[0].InnerText != string.Empty)
                        {
                            string subMotivoFiltrado = UtilController.ObtenerAtributoParametricaByCod("P_SubMotivoOT", "Cod", row.SelectNodes("Column[@Name='P_SUBMOTIVOOT_COD']")[0].InnerText, "SubMotivo");
                            fila.Add(subMotivoFiltrado);
                        }
                        fila.Add(@"<a href='" + Url.Action("TratarCaso", "TratarCaso", new { id = numCasoXML }) + @"' class='btn btn-default btn-md center-block'>Tratar</a>");


                        // Agregar a lista FORMA CORRECTA
                        if (valido)
                        {
                            registros.Add(fila);
                        }
                    }
                    datosJSON = JsonConvert.SerializeObject(registros);

                    //Escribir log CSV
                    UtilController.EscribirLog("Caso rescatado", "CasosPendientes", datosJSON);
                    //Fin CSV
                }
            }
            catch (Exception ex)
            {
                //Escribir log CSV
                UtilController.EscribirLog("ERROR", "CasosPendientes", ex.Message);
                //Fin CSV
            }
            return(datosJSON);
        }