public HttpResponseMessage GrabarArchivoRelacionesLaborales(List <EDRelacionesLaborales> lstRelLabTer)
 {
     try
     {
         LNRelacionesLaborales lnRL = new LNRelacionesLaborales();/// Defino variable gs
         string mensaje_bd          = "";
         EDRelacionesLaborales edRL = new EDRelacionesLaborales();
         edRL.Rta = lnRL.GrabarArchivoRelacionesLaborales(lstRelLabTer, out mensaje_bd);
         edRL.Mensaje_validacion = mensaje_bd;
         List <EDRelacionesLaborales> lstedRL = new List <EDRelacionesLaborales>();
         lstedRL.Add(edRL);
         var response = Request.CreateResponse <List <EDRelacionesLaborales> >(HttpStatusCode.Created, lstedRL);
         return(response);
     }
     catch (Exception ex)
     {
         var response = Request.CreateResponse(HttpStatusCode.InternalServerError);
         return(response);
     }
 }
Exemplo n.º 2
0
        public ActionResult CargarArchivoRelacionesLaborales(HttpPostedFileBase ArchivoRelacionesLaborales)
        {
            var    path = "";
            bool   rta  = true;
            string mensaje_validacion = "";

            ViewBag.MessagesOK  = "";
            ViewBag.MessagesERR = "";

            var usuarioActual = ObtenerUsuarioEnSesion(System.Web.HttpContext.Current);

            if (usuarioActual == null)
            {
                ViewBag.Mensaje = "Debe estar autenticado para realizar la evalación.";
                return(RedirectToAction("Login", "Home"));
            }

            if (ArchivoRelacionesLaborales != null && ArchivoRelacionesLaborales.ContentLength > 0)
            {
                if (Path.GetExtension(ArchivoRelacionesLaborales.FileName).ToLower() == ".xls")
                {
                    path = Path.Combine(Server.MapPath("~/Content/ArchivosRelacionesLaborales"), usuarioActual.NitEmpresa + ".xls");
                    ArchivoRelacionesLaborales.SaveAs(path);
                    ViewBag.UploadSuccess = true;
                    try
                    {
                        var usuario = ObtenerUsuarioEnSesion(System.Web.HttpContext.Current);
                        //creamos el libro a partir de la ruta
                        //var resp = ReadFileCVS(path, usuario.IdEmpresa);
                        var Book = new ExcelQueryFactory(path);
                        //Consulta con Linq
                        var resp = (from row in Book.Worksheet("RELACIONES LABORALES")
                                    let item = new EDRelacionesLaborales
                        {
                            //Id_Tematica = row[0].Cast<string>();
                            TipoTercero = ValidarNullCell(row, 0),
                            NitEmpresa = ValidarNullCell(row, 1),
                            RazonSocial = ValidarNullCell(row, 2),
                            TipoDocumento = ValidarNullCell(row, 3),
                            NumeroDocumento = ValidarNullCell(row, 4),
                            Apellido1 = ValidarNullCell(row, 5),
                            Apellido2 = ValidarNullCell(row, 6),
                            Nombre1 = ValidarNullCell(row, 7),
                            Nombre2 = ValidarNullCell(row, 8),
                            FechaNacimiento = ValidarNullCell(row, 9),
                            Ocupacion = ValidarNullCell(row, 10),
                            Cargo = ValidarNullCell(row, 11),
                            Email = ValidarNullCell(row, 12),
                            idEmpresa = usuario.IdEmpresa.ToString()
                        }
                                    select item).ToList();

                        Book.Dispose();
                        //resp = ValidarFilaVacia(resp);
                        //rta = lnRL.GrabarArchivoRelacionesLaborales(resp, out mensaje_validacion);
                        ServiceClient.EliminarParametros();
                        var result = ServiceClient.RealizarPeticionesPostJsonRestFul <List <EDRelacionesLaborales> >(urlServicioEmpresas, CapacidadRelacionlaboralArchivoRelacionesLaborales, resp);

                        if (result.Count() > 0)
                        {
                            EDRelacionesLaborales euRL = result[0];
                            rta = euRL.Rta;
                            mensaje_validacion = euRL.Mensaje_validacion;
                        }
                    }
                    catch (System.Exception ex)
                    {
                        rta = false;
                        ViewBag.MessagesERR = "Error en el formato del archivo. por favor verifique.";
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }
                }
                else
                {
                    rta = false;
                    ViewBag.MessagesERR = "Error en el formato del archivo. por favor verifique.";
                }
            }
            else
            {
                ViewBag.MessagesERR = "No ha seleccionado un documento para cargar";
                return(View("Index"));
            }
            if (rta)
            {
                ViewBag.ErrorProcesaArchivo = false;
                ViewBag.MessagesOK          = "Documento cargado correctamente";

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                return(View("Index"));
            }
            else
            {
                ViewBag.ErrorProcesaArchivo = true;
                ViewBag.MessagesERR         = (mensaje_validacion == "") ? ViewBag.MessagesERR: mensaje_validacion;

                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }

                return(View("Index"));
            }
        }