Exemple #1
0
 public IHttpActionResult GuardarInstructor(Instructor oInstructor)
 {
     try
     {
         VirtualidadBl oInstructorBl = new VirtualidadBl();
         var           Instructor    = oInstructorBl.GuardarInstructor(oInstructor);
         if (Instructor == true)
         {
             return(Ok(new { success = true }));
         }
         else
         {
             return(Ok(new { success = false }));
         }
     }
     catch (Exception exc)
     {
         return(Ok(new { success = false, exc = exc.Message }));
     }
 }
Exemple #2
0
        public IHttpActionResult UploadFileInstructor()
        {
            try
            {
                //                List<LogResponseDTO> lstErrores = new List<LogResponseDTO>();
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    var fileSavePath = string.Empty;

                    var docfiles = new List <string>();

                    var URLArchivo = "";

                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        //  var filePath = HttpContext.Current.Server.MapPath("C:/UploadedFiles/");
                        var filePath = "C:/UploadedFiles/";

                        var GUID = Guid.NewGuid().ToString();

                        if (!Directory.Exists(filePath))
                        {
                            Directory.CreateDirectory(filePath);
                        }

                        fileSavePath = Path.Combine(filePath, GUID + "." + postedFile.FileName.Split('.')[1]);



                        postedFile.SaveAs(fileSavePath);

                        docfiles.Add(filePath);

                        // URLArchivo = "~/UploadedFiles/" + GUID + "." + postedFile.FileName.Split('.')[1];
                        URLArchivo = "C:/UploadedFiles/" + GUID + "." + postedFile.FileName.Split('.')[1];


                        string e = Path.GetExtension(URLArchivo);
                        if ((e != ".xlsx") && (e != ".xlsm"))
                        {
                            return(Ok(new { success = false, message = "La extencion del archivo no es válida" }));
                        }
                    }

                    string FilePath = URLArchivo.Split('/')[1];

                    // var reader = new StreamReader(File.OpenRead(HttpContext.Current.Server.MapPath("~/UploadedFiles/") + FilePath), Encoding.GetEncoding(1252));
                    //var reader = new StreamReader(File.OpenRead(("C:/UploadedFiles/") + FilePath), Encoding.GetEncoding(1252));


                    Instructor    oInstructor    = new Instructor();
                    VirtualidadBl oVirtualidadBL = new VirtualidadBl();

                    var book = new ExcelQueryFactory(URLArchivo);

                    var resultado = (from row in book.Worksheet("Hoja1")
                                     select row).ToList();

                    foreach (var values in resultado)
                    {
                        if (values[12] != "AREA")
                        {
                            var Inst = oVirtualidadBL.InstructorCedula(values[1]);

                            if (Inst == null)
                            {
                                oInstructor.Numero            = values[0];
                                oInstructor.Area              = values[12];
                                oInstructor.Cedula            = values[1];
                                oInstructor.Nombre            = values[2];
                                oInstructor.Apellido          = values[3];
                                oInstructor.Email             = values[4];
                                oInstructor.EmailAlternativo  = values[5];
                                oInstructor.MunicipioVivienda = values[6];
                                oInstructor.Telefono          = values[7];
                                oInstructor.Celular           = values[8];
                                oInstructor.DiaNacimiento     = values[9];
                                oInstructor.MesNacimiento     = values[10];
                                oInstructor.AnioNacimiento    = values[11];
                                oInstructor.Inicio_Contrato   = values[14];
                                oInstructor.Fin_Contrato      = values[15];
                                oInstructor.Profesion         = values[16];
                                oInstructor.ProgramaFormacion = values[17];
                                oInstructor.TipoContrato      = values[18];
                                oInstructor.Estado            = true;
                                oInstructor.EnvioCorreo       = false;
                                oInstructor.Num_Contrato      = "";
                                oInstructor.Adicion           = "";

                                oVirtualidadBL.GuardarInstructor(oInstructor);
                            }
                            else
                            {
                                return(Ok(new { success = false, message = "No se encontró archivo" }));
                            }
                        }
                    }

                    return(Ok(new { success = true, path = URLArchivo }));
                }
                else
                {
                    return(Ok(new { success = false, message = "No File" }));
                }
            }
            catch (Exception exc)
            {
                return(Ok(new { success = false, message = exc.Message }));
            }
        }