Пример #1
0
        public IHttpActionResult GuardarFicha(Ficha oFicha)
        {
            try
            {
                bool respuesta = false;

                FichaBl oFichaBl = new FichaBl();
                respuesta = oFichaBl.GuardarFicha(oFicha);
                return(Ok(new { respuesta, success = true }));
            }
            catch (Exception exc)
            {
                return(Ok(new { success = false, exc = exc.Message }));
            }
        }
Пример #2
0
        public IHttpActionResult UploadFileFicha()
        {
            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("~/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")
                        {
                            return(Ok(new { success = false, message = "La extencion del archivo no es valida" }));
                        }
                    }

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

                    //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));

                    Ficha         oFicha   = new Ficha();
                    FichaBl       oFichaBl = new FichaBl();
                    List <string> idProgramasNoRegistro = new List <string>();

                    ProgramaBl oProgramaBl = new ProgramaBl();

                    var book      = new ExcelQueryFactory(URLArchivo);
                    var hoja      = book.GetWorksheetNames();
                    var resultado = (from i in book.Worksheet(hoja.FirstOrDefault())
                                     select i).ToList();

                    foreach (var values in resultado)
                    {
                        if (values[0] == "")
                        {
                            break;
                        }
                        var Programa = oProgramaBl.ConsultarProgramaCodigo(int.Parse(values[0]));

                        if (Programa == null)
                        {
                            idProgramasNoRegistro.Add(values[0]);
                            continue;
                        }
                        oFicha.IdPrograma    = oProgramaBl.ConsultarProgramaCodigo(int.Parse(values[0])).IdPrograma;
                        oFicha.Ficha1        = values[1];
                        oFicha.NumAprendices = int.Parse(values[2]);
                        oFicha.TipoFormacion = values[3].ToString();
                        oFicha.Jornada       = values[6].ToString();

                        if (DateTime.Parse(values[4]) <= DateTime.Parse(values[5]))
                        {
                            oFicha.FechaInicio = DateTime.Parse(values[4]);
                            oFicha.FechaFin    = DateTime.Parse(values[5]);
                        }

                        oFicha.Estado = true;
                        oFichaBl.GuardarFicha(oFicha);
                    }
                    var no = idProgramasNoRegistro;

                    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 }));
            }
        }