public IHttpActionResult GuardarPrograma(Programa oPrograma) { try { ProgramaBl oProgramaBl = new ProgramaBl(); return(Ok(new { success = oProgramaBl.GuardarPrograma(oPrograma) })); } catch (Exception exc) { return(Ok(new { success = false, exc = exc.Message })); } }
public IHttpActionResult UploadFilePrograma() { 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)); Programa oPrograma = new Programa(); ProgramaBl oProgramaBl = new ProgramaBl(); List <string> ProgramaNoRegistro = new List <string>(); Area oArea = new Area(); AreaBl oAreaBl = new AreaBl(); var book = new ExcelQueryFactory(URLArchivo); var hoja = book.GetWorksheetNames(); var resultado = (from i in book.Worksheet(hoja.FirstOrDefault()) select i).ToList(); var contador = 0; foreach (var values in resultado) { if (values[0] == "") { break; } var codigo = oProgramaBl.ConsultarProgramaCodigo(int.Parse(values[0].ToString())); if (codigo != null) { ProgramaNoRegistro.Add(values[1]); continue; } if (codigo == null) { oPrograma.CodigoPrograma = int.Parse(values[0].ToString()); oPrograma.NombrePrograma = values[1]; oPrograma.Nivel = values[2]; oPrograma.LineaTecnologica = values[3]; oPrograma.Red_Tecnologica = values[4]; oPrograma.Perfil_Instructor = values[5]; oPrograma.Version_Programa = double.Parse(values[6]); oPrograma.IdArea = oAreaBl.ConsultarAreaCodigo(int.Parse(values[7])).IdArea; oProgramaBl.GuardarPrograma(oPrograma); contador++; } } var no = ProgramaNoRegistro; 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 })); } }