parent
d4c5c82720
commit
86e7daab3b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,12 @@ |
|||||||
|
using AOLBackend.Models.Utils; |
||||||
|
namespace AOLBackend.Contracts.Utils |
||||||
|
{ |
||||||
|
public interface IFileManagerRepository |
||||||
|
{ |
||||||
|
public Task<FileManager> FileManager(FileManager data); |
||||||
|
public Task<FileManager> getFileByProcess(long id, int Proceso); |
||||||
|
public Task<List<FileManager>> getAllFilesByProcess(long Tags, int Proceso); |
||||||
|
public Task<FileManager> getFileById(long id); |
||||||
|
public Task deleteFileByProcess(long id, int Proceso); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,9 @@ |
|||||||
|
using AOLBackend.Models.Utils; |
||||||
|
|
||||||
|
namespace AOLBackend.Contracts.Utils |
||||||
|
{ |
||||||
|
public interface IFilePaths4ProcessRepository |
||||||
|
{ |
||||||
|
public Task<FilePaths4Process> getPaths4ProcessById(long id); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,148 @@ |
|||||||
|
using AOLBackend.Contracts.Utils; |
||||||
|
using AOLBackend.Models.Utils; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace AOLBackend.Controllers.Utils |
||||||
|
{ |
||||||
|
[ApiController] |
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class FileManagerController : ControllerBase |
||||||
|
{ |
||||||
|
|
||||||
|
private readonly IFileManagerRepository _Repo; |
||||||
|
private readonly IFilePaths4ProcessRepository _RepoRelativePath; |
||||||
|
private readonly IConfiguration _config; |
||||||
|
private readonly string RootPathCorresponsales; |
||||||
|
public FileManagerController(IFileManagerRepository Repo, |
||||||
|
IFilePaths4ProcessRepository RepoRelativePath, |
||||||
|
IConfiguration config) |
||||||
|
{ |
||||||
|
_config = config; |
||||||
|
_Repo = Repo; |
||||||
|
_RepoRelativePath = RepoRelativePath; |
||||||
|
RootPathCorresponsales = _config.GetValue<string>("AllFiles"); |
||||||
|
} |
||||||
|
|
||||||
|
[Route("GetFileInfoByProcess")] |
||||||
|
[HttpGet] |
||||||
|
public async Task<FileManager> GetFileInfoByProcess([FromQuery] int id, int Proceso) |
||||||
|
{ |
||||||
|
FileManager data = new FileManager(); |
||||||
|
data = await _Repo.getFileByProcess(id, Proceso); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
[Route("GetFileInfoById")] |
||||||
|
[HttpGet] |
||||||
|
public async Task<FileManager> GetFileInfoByProcess([FromQuery] int id) |
||||||
|
{ |
||||||
|
FileManager data = new FileManager(); |
||||||
|
data = await _Repo.getFileById(id); |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
[Route("AppendFileByProcess")] |
||||||
|
[HttpPost] |
||||||
|
public async Task<FileManager> AppendFileByProcess(IFormFile file, int IdUsuario, int Proceso, string Tags, int crud) |
||||||
|
{ |
||||||
|
DateTime time = DateTime.Now; |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
||||||
|
string fullPath = ""; |
||||||
|
fullPath = RootPathCorresponsales + RelativePath.Path; |
||||||
|
string fileMime = file.FileName.Substring(file.FileName.Length - 4); |
||||||
|
string newFileName = file.FileName.Replace(fileMime, "") + "_" + time.ToString("yyyy_MM_dd_HH_mm_ss") + fileMime; |
||||||
|
FileManager data = new FileManager(); |
||||||
|
data.id = 0; |
||||||
|
data.IdUsuario = IdUsuario; |
||||||
|
data.NombreArchivo = newFileName; |
||||||
|
data.Proceso = Proceso; |
||||||
|
data.FechaRegistro = ""; |
||||||
|
data.Tags = Tags; |
||||||
|
data.Activo = 1; |
||||||
|
long fileLength = 0; |
||||||
|
if (@crud == 1) |
||||||
|
{ |
||||||
|
if (file.Length > 0) |
||||||
|
{ |
||||||
|
var filePath = fullPath + newFileName; |
||||||
|
using (var stream = System.IO.File.Create(filePath)) |
||||||
|
{ |
||||||
|
await file.CopyToAsync(stream); |
||||||
|
} |
||||||
|
fileLength = new System.IO.FileInfo(filePath).Length / 1024; |
||||||
|
data.Size = fileLength; |
||||||
|
if (fileLength > 0) |
||||||
|
{ |
||||||
|
return await _Repo.FileManager(data); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return data; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[Route("getFile")] |
||||||
|
[HttpGet, DisableRequestSizeLimit] |
||||||
|
public async Task<IActionResult> getFileFromFileManager([FromQuery] long id, int Proceso) |
||||||
|
{ |
||||||
|
Boolean ExisteEnDisco = false; |
||||||
|
FileManager recFound = await _Repo.getFileByProcess(id, Proceso); |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
||||||
|
string fullPath = ""; |
||||||
|
fullPath = RootPathCorresponsales + RelativePath.Path; |
||||||
|
if (!String.IsNullOrEmpty(recFound.NombreArchivo)) |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
if (System.IO.File.Exists(Path.Combine(fullPath, recFound.NombreArchivo))) |
||||||
|
{ |
||||||
|
ExisteEnDisco = true; |
||||||
|
} |
||||||
|
else return BadRequest(new { respuesta = "Ese archivo no existe" }); |
||||||
|
} |
||||||
|
catch (IOException ex) |
||||||
|
{ |
||||||
|
return BadRequest(new { respuesta = "Ese archivo no existe" + ex.ToString() }); |
||||||
|
} |
||||||
|
if (ExisteEnDisco) |
||||||
|
{ |
||||||
|
string fileMime = recFound.NombreArchivo.Substring(recFound.NombreArchivo.Length - 3).ToLower(); |
||||||
|
var mime = "application/" + fileMime.ToLower(); |
||||||
|
string targetFile = fullPath + recFound.NombreArchivo; |
||||||
|
if (System.IO.File.Exists(targetFile)) |
||||||
|
{ |
||||||
|
byte[] pdfBytes = System.IO.File.ReadAllBytes(targetFile); |
||||||
|
MemoryStream ms = new MemoryStream(pdfBytes); |
||||||
|
return new FileStreamResult(ms, mime); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return BadRequest(new { respuesta = "Ese archivo no existe" }); |
||||||
|
} |
||||||
|
|
||||||
|
[HttpDelete("DeleteById/{id}")] |
||||||
|
public async Task<IActionResult> DeleteByProcess(long id) |
||||||
|
{ |
||||||
|
FileManager Found = await _Repo.getFileById(id); |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Found.Proceso); |
||||||
|
string fullPath = ""; |
||||||
|
fullPath = RootPathCorresponsales + RelativePath.Path; |
||||||
|
try |
||||||
|
{ |
||||||
|
if (System.IO.File.Exists(Path.Combine(fullPath, Found.NombreArchivo))) |
||||||
|
{ |
||||||
|
System.IO.File.Delete(Path.Combine(fullPath, Found.NombreArchivo)); |
||||||
|
await _Repo.deleteFileByProcess(Found.id, Found.Proceso); |
||||||
|
} |
||||||
|
else return new OkObjectResult(new { respuesta = "Ese archivo no existe" }); |
||||||
|
} |
||||||
|
catch (IOException ex) |
||||||
|
{ |
||||||
|
return new OkObjectResult(new { respuesta = "Ocurrio un error al intentar eliminar el registro: " + ex.ToString() }); |
||||||
|
} |
||||||
|
return new OkObjectResult(new { respuesta = "Se elimino el registro" }); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,56 @@ |
|||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
using AOLBackend.Services.MFileManager; |
||||||
|
using AOLBackend.Contracts.Utils; |
||||||
|
using AOLBackend.Models.Utils; |
||||||
|
|
||||||
|
namespace AOLBackend.Controllers.Utils |
||||||
|
{ |
||||||
|
[Route("api/Utils/[controller]")]
|
||||||
|
public class MFileManagerController : Controller |
||||||
|
{ |
||||||
|
private readonly IFileManagerRepository _Repo; |
||||||
|
private readonly IConfiguration _config; |
||||||
|
private readonly IFilePaths4ProcessRepository _RepoRelativePath; |
||||||
|
private readonly string RootPath; |
||||||
|
|
||||||
|
public MFileManagerController(IConfiguration config, IFilePaths4ProcessRepository RepoRelativePath, IFileManagerRepository Repo) |
||||||
|
{ |
||||||
|
_config = config; |
||||||
|
_RepoRelativePath = RepoRelativePath; |
||||||
|
_Repo = Repo; |
||||||
|
RootPath = _config.GetValue<string>("AllFiles"); |
||||||
|
} |
||||||
|
|
||||||
|
[HttpGet] |
||||||
|
[Route("GetFilesFromLog")] |
||||||
|
public async Task<List<FileManager>> GetFilesFromLog(int Tags, int Proceso) |
||||||
|
{ |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
||||||
|
SvcMFileManager FM = new SvcMFileManager(_config, _Repo, RootPath + RelativePath.Path); |
||||||
|
return await FM.GetFilesFromLog(Tags, Proceso); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[HttpGet] |
||||||
|
[Route("GetFileContentById")] |
||||||
|
public async Task<IActionResult> GetFileContentById(long id, int Proceso) |
||||||
|
{ |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
||||||
|
SvcMFileManager FM = new SvcMFileManager(_config, _Repo, RootPath + RelativePath.Path); |
||||||
|
return await FM.getFileContentById(id); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
[HttpPost] |
||||||
|
[Route("Append")] |
||||||
|
public async Task<List<FileManager>> Append(List<IFormFile> FileList, int Tags, int Proceso, int Usuario) |
||||||
|
{ |
||||||
|
List<string> data = new List<string>(); |
||||||
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
||||||
|
SvcMFileManager FM = new SvcMFileManager(_config, _Repo, RootPath + RelativePath.Path); |
||||||
|
List<string> filePaths = await FM.SaveFile2DiskList(FileList); |
||||||
|
var fileData = await FM.SaveFileLog(filePaths, Tags, Proceso, Usuario); |
||||||
|
return fileData; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,14 @@ |
|||||||
|
namespace AOLBackend.Models.Utils |
||||||
|
{ |
||||||
|
public class FileManager |
||||||
|
{ |
||||||
|
public long id { get; set; } = 0!; |
||||||
|
public int IdUsuario { get; set; } = 0!; |
||||||
|
public int Proceso { get; set; } = 0!; |
||||||
|
public string NombreArchivo { get; set; } = null!; |
||||||
|
public string FechaRegistro { get; set; } = null!; |
||||||
|
public string Tags { get; set; } = null!; |
||||||
|
public long Size { get; set; } = 0!; |
||||||
|
public byte Activo { get; set; } = 0!; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,7 @@ |
|||||||
|
namespace AOLBackend.Models.Utils |
||||||
|
{ |
||||||
|
public class FilePaths4Process |
||||||
|
{ |
||||||
|
public string Path { set; get; } = string.Empty; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,88 @@ |
|||||||
|
using Dapper; |
||||||
|
using AOLBackend.Context; |
||||||
|
using AOLBackend.Contracts.Utils; |
||||||
|
using AOLBackend.Models.Utils; |
||||||
|
using System.Data; |
||||||
|
|
||||||
|
namespace AOLBackend.Repository.Utils |
||||||
|
{ |
||||||
|
public class FileManagerRepository : IFileManagerRepository |
||||||
|
{ |
||||||
|
private readonly DapperContext _context; |
||||||
|
public FileManagerRepository(DapperContext context) { _context = context; } |
||||||
|
|
||||||
|
public async Task<FileManager> FileManager(FileManager data) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.Append]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FileManager>(query, new |
||||||
|
{ |
||||||
|
@id = 0, |
||||||
|
@IdUsuario = data.IdUsuario, |
||||||
|
@Proceso = data.Proceso, |
||||||
|
@NombreArchivo = data.NombreArchivo, |
||||||
|
@Tags = data.Tags, |
||||||
|
@Size = data.Size |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
return entrada.First(); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<FileManager> getFileByProcess(long id, int Proceso) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.Get]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FileManager>(query, new |
||||||
|
{ |
||||||
|
@id = 0, |
||||||
|
@Proceso = Proceso, |
||||||
|
@NombreArchivo = "", |
||||||
|
@Tags = id, |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
return entrada.FirstOrDefault(new FileManager { id = id, Proceso = Proceso, NombreArchivo = "", Tags = "", Size = 0 }); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<FileManager> getFileById(long id) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.Get]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FileManager>(query, new |
||||||
|
{ |
||||||
|
@id = id, |
||||||
|
@Proceso = 0, |
||||||
|
@NombreArchivo = "", |
||||||
|
@Tags = id, |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
return entrada.FirstOrDefault(new FileManager { id = id, Proceso = 0, NombreArchivo = "", Tags = "", Size = 0 }); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<List<FileManager>> getAllFilesByProcess(long Tags, int Proceso) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.Get]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FileManager>(query, new |
||||||
|
{ |
||||||
|
@id = 0, |
||||||
|
@Proceso = Proceso, |
||||||
|
@NombreArchivo = "", |
||||||
|
@Tags = Tags, |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
return entrada.ToList(); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task deleteFileByProcess(long id, int Proceso) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.Delete]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FileManager>(query, new |
||||||
|
{ |
||||||
|
@id = id, |
||||||
|
@Proceso = Proceso, |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,26 @@ |
|||||||
|
using Dapper; |
||||||
|
using AOLBackend.Contracts.Utils; |
||||||
|
using AOLBackend.Context; |
||||||
|
using AOLBackend.Models.Utils; |
||||||
|
using System.Data; |
||||||
|
|
||||||
|
namespace AOLBackend.Repository.Utils |
||||||
|
{ |
||||||
|
public class FilePaths4ProcessRepository : IFilePaths4ProcessRepository |
||||||
|
{ |
||||||
|
private readonly DapperContext _context; |
||||||
|
public FilePaths4ProcessRepository(DapperContext context) { _context = context; } |
||||||
|
|
||||||
|
public async Task<FilePaths4Process> getPaths4ProcessById(long id) |
||||||
|
{ |
||||||
|
var query = "[Utils.FileManager.RootPath.Get]"; |
||||||
|
using var connection = _context.CreateConnection(); |
||||||
|
var entrada = await connection.QueryAsync<FilePaths4Process>(query, new |
||||||
|
{ |
||||||
|
@id = id, |
||||||
|
}, |
||||||
|
commandType: CommandType.StoredProcedure); |
||||||
|
return entrada.First(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,57 @@ |
|||||||
|
using System.Net; |
||||||
|
using System.Net.Mail; |
||||||
|
|
||||||
|
namespace AOLBackend.Services.EmailSender |
||||||
|
{ |
||||||
|
public class EmailSender |
||||||
|
{ |
||||||
|
private IConfiguration _config; |
||||||
|
|
||||||
|
public EmailSender(IConfiguration config) |
||||||
|
{ |
||||||
|
_config = config; |
||||||
|
} |
||||||
|
public Boolean SendEmail(string htmlContent, Usuarios toUser) |
||||||
|
{ |
||||||
|
string defaultPassword = _config.GetValue<string>("DefaultUser:Password"); |
||||||
|
string emailServer = _config.GetValue<string>("EmailServer"); |
||||||
|
int emailPort = _config.GetValue<int>("EmailPort"); |
||||||
|
htmlContent = (htmlContent.Length > 0) ? htmlContent : $@"<html>
|
||||||
|
<body> |
||||||
|
<table style='font-size:14px; border: 1px solid #225EDD; padding: 5px; width: 1500px; height: 150px;'> |
||||||
|
<tr style='background-color: #225EDD; color: #FFFFFF;'><td>Hola: {toUser.Nombre}, mediante el siguiente correo electronico, se le notifica que se le ha creado un nuevo acceso</td></tr> |
||||||
|
<tr><td>Para acceder a su cuenta, favor de entrar a: http://reportes.gemcousa.com/</td></tr> |
||||||
|
<tr><td>Nombre de usuario: <b>{toUser.Usuario}</b></td></tr> |
||||||
|
<tr><td>Contraseña: <b>{defaultPassword}</b></td></tr> |
||||||
|
<tr><td>Su contraseña inicial sera: {defaultPassword}, pero es necesario que la cambie antes de poder ingresar</td></tr> |
||||||
|
<tr><td>Para cambiar la contraseña, puede ir al menu Reset, proporcione su nombre de usuario y su nueva contraseña</td></tr> |
||||||
|
<tr><td>Si por alguna razon, no recuerda su contrasena, repita este proceso de resetear su contraseña</td></tr> |
||||||
|
<tr><td>No es necesario responder a este correo, ya que fue generado en automatico por el sistema.</td></tr> |
||||||
|
<tr style='background-color: #F7192A; font-weight: bold; color: #FFFFFF'><td>Nota: Las credenciales de acceso son responsabilidad personal, nadie solo usted debe conocerlas</td></tr> |
||||||
|
<tr><td>Que tenga un excelente dia!</td></tr> |
||||||
|
</table> |
||||||
|
</body> |
||||||
|
</html> ";
|
||||||
|
try |
||||||
|
{ |
||||||
|
using (var smtp = new SmtpClient(emailServer, emailPort)) |
||||||
|
{ |
||||||
|
smtp.Credentials = new NetworkCredential(_config.GetValue<string>("Email"), _config.GetValue<string>("EmailPassword")); |
||||||
|
var correo = new MailMessage(); |
||||||
|
correo.From = new MailAddress(_config.GetValue<string>("Email"), "noreply"); |
||||||
|
correo.To.Add(toUser.Correo); |
||||||
|
correo.Subject = "Notification - Se le ha creado un nuevo acceso en http://reportes.gemcousa.com"; |
||||||
|
correo.Body = htmlContent; |
||||||
|
correo.IsBodyHtml = true; |
||||||
|
smtp.Send(correo); |
||||||
|
return true; |
||||||
|
} |
||||||
|
} |
||||||
|
catch (Exception ex) |
||||||
|
{ |
||||||
|
//if (ex.Source != null) throw; |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,106 @@ |
|||||||
|
using AOLBackend.Models.Utils; |
||||||
|
using AOLBackend.Contracts.Utils; |
||||||
|
using Microsoft.AspNetCore.Mvc; |
||||||
|
|
||||||
|
namespace AOLBackend.Services.MFileManager |
||||||
|
{ |
||||||
|
public class SvcMFileManager |
||||||
|
{ |
||||||
|
private readonly IFileManagerRepository _Repo; |
||||||
|
private readonly IConfiguration _config; |
||||||
|
// private readonly IFilePaths4ProcessRepository _RepoRelativePath; |
||||||
|
private readonly string rootPath; |
||||||
|
|
||||||
|
public SvcMFileManager(IConfiguration config, IFileManagerRepository Repo, string _rootPath) |
||||||
|
{ |
||||||
|
_config = config; |
||||||
|
_Repo = Repo; |
||||||
|
rootPath = _rootPath; |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<List<FileManager>> GetFilesFromLog(int Tags, int Proceso) |
||||||
|
{ |
||||||
|
return await _Repo.getAllFilesByProcess(Tags, Proceso); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<IActionResult> getFileContentById(long id) |
||||||
|
{ |
||||||
|
Boolean ExisteEnDisco = false; |
||||||
|
byte[] emptyFile = System.IO.File.ReadAllBytes("c:\\downs\\empty.png"); |
||||||
|
//byte[] emptyFile = System.IO.File.ReadAllBytes("D:\\data\\empty.png"); |
||||||
|
MemoryStream emptyms = new MemoryStream(emptyFile); |
||||||
|
FileManager recFound = await _Repo.getFileById(id); |
||||||
|
if (!String.IsNullOrEmpty(recFound.NombreArchivo)) |
||||||
|
{ |
||||||
|
try |
||||||
|
{ |
||||||
|
if (System.IO.File.Exists(Path.Combine(rootPath, recFound.NombreArchivo))) |
||||||
|
{ |
||||||
|
ExisteEnDisco = true; |
||||||
|
} |
||||||
|
else |
||||||
|
{ |
||||||
|
return new FileStreamResult(emptyms, "image/png"); |
||||||
|
} |
||||||
|
} |
||||||
|
catch (IOException ex) |
||||||
|
{ |
||||||
|
return new FileStreamResult(emptyms, "image/png"); |
||||||
|
} |
||||||
|
if (ExisteEnDisco) |
||||||
|
{ |
||||||
|
string fileMime = recFound.NombreArchivo.Substring(recFound.NombreArchivo.Length - 3).ToLower(); |
||||||
|
var mime = "application/" + fileMime.ToLower(); |
||||||
|
string targetFile = rootPath + recFound.NombreArchivo; |
||||||
|
if (System.IO.File.Exists(targetFile)) |
||||||
|
{ |
||||||
|
byte[] pdfBytes = System.IO.File.ReadAllBytes(targetFile); |
||||||
|
MemoryStream ms = new MemoryStream(pdfBytes); |
||||||
|
return new FileStreamResult(ms, mime); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return new FileStreamResult(emptyms, "image/png"); |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<List<string>> SaveFile2DiskList(List<IFormFile> FileList) |
||||||
|
{ |
||||||
|
DateTime time = DateTime.Now; |
||||||
|
var filePaths = new List<string>(); |
||||||
|
FileManager data = new FileManager(); |
||||||
|
foreach (var file in FileList) |
||||||
|
{ |
||||||
|
string fileMime = file.FileName.Substring(file.FileName.Length - 4); |
||||||
|
string newFileName = file.FileName.Replace(fileMime, "") + "_" + time.ToString("yyyy_MM_dd_HH_mm_ss") + fileMime; |
||||||
|
if (file.Length > 0) |
||||||
|
{ |
||||||
|
var filePath = rootPath + newFileName; |
||||||
|
using (var stream = System.IO.File.Create(filePath)) |
||||||
|
{ |
||||||
|
await file.CopyToAsync(stream); |
||||||
|
filePaths.Add(newFileName); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
return filePaths; |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<List<FileManager>> SaveFileLog(List<string> files, int Tags, int Proceso, int Usuario) |
||||||
|
{ |
||||||
|
List<FileManager> resultados = new List<FileManager>(); |
||||||
|
foreach (string file in files) |
||||||
|
{ |
||||||
|
FileManager data = new FileManager(); |
||||||
|
long fileLength = new System.IO.FileInfo(rootPath + file).Length / 1024; |
||||||
|
data.id = 0; |
||||||
|
data.IdUsuario = Usuario; |
||||||
|
data.Proceso = Proceso; |
||||||
|
data.NombreArchivo = file; |
||||||
|
data.Tags = Tags.ToString(); |
||||||
|
data.Size = fileLength; |
||||||
|
await _Repo.FileManager(data); |
||||||
|
} |
||||||
|
return await _Repo.getAllFilesByProcess(Tags, Proceso); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Binary file not shown.
Binary file not shown.
@ -1 +1 @@ |
|||||||
eefe8f67b06397f0ffbb2eddb23dd69eb10fac57 |
543d6e2052e74dfe9cc3f60cc2cb0d6f72d7753c |
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue