Permite subir documentos al monitor de viajes

develop
Al Garcia 2 years ago
parent d4c5c82720
commit 86e7daab3b
  1. BIN
      .vs/AOLBackend/DesignTimeBuild/.dtbcache.v2
  2. BIN
      .vs/AOLBackend/v17/.futdcache.v1
  3. BIN
      .vs/AOLBackend/v17/.suo
  4. BIN
      .vs/ProjectEvaluation/aolbackend.metadata.v2
  5. BIN
      .vs/ProjectEvaluation/aolbackend.projects.v2
  6. 12
      Contracts/Utils/IFileManagerRepository.cs
  7. 9
      Contracts/Utils/IFilePaths4ProcessRepository.cs
  8. 1
      Controllers/Usuarios/AuthController.cs
  9. 8
      Controllers/Usuarios/UsuariosController.cs
  10. 148
      Controllers/Utils/FileManagerController.cs
  11. 56
      Controllers/Utils/MFileManagerController.cs
  12. 24
      Models/IUsuarios.cs
  13. 14
      Models/Utils/FileManager.cs
  14. 7
      Models/Utils/FilePaths4Process.cs
  15. 9
      Program.cs
  16. 7
      Repository/UsuariosRepository.cs
  17. 88
      Repository/Utils/FileManagerRepository.cs
  18. 26
      Repository/Utils/FilePaths4ProcessRepository.cs
  19. 57
      Services/EmailSender/EmailSender.cs
  20. 106
      Services/MFileManager/SvcMFileManager.cs
  21. 2
      appsettings.json
  22. BIN
      bin/Debug/net6.0/AOLBackend.dll
  23. BIN
      bin/Debug/net6.0/AOLBackend.pdb
  24. 2
      obj/Debug/net6.0/AOLBackend.csproj.CoreCompileInputs.cache
  25. BIN
      obj/Debug/net6.0/AOLBackend.dll
  26. BIN
      obj/Debug/net6.0/AOLBackend.pdb
  27. BIN
      obj/Debug/net6.0/ref/AOLBackend.dll
  28. BIN
      obj/Debug/net6.0/refint/AOLBackend.dll
  29. 63
      obj/staticwebassets.pack.sentinel

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

@ -48,7 +48,6 @@ namespace AOLBackend.Controllers.Usuarios
claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString())); claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString()));
claims.Add(new Claim("UserId", user.Id.ToString())); claims.Add(new Claim("UserId", user.Id.ToString()));
claims.Add(new Claim("Usuario", user.Usuario)); claims.Add(new Claim("Usuario", user.Usuario));
claims.Add(new Claim("Departamento", (user.sDept ?? user.sDept ?? "No asignado")));
claims.Add(new Claim("UserType", (user != null) ? user.TipoUsuario.ToString() : "0")); claims.Add(new Claim("UserType", (user != null) ? user.TipoUsuario.ToString() : "0"));
if (menu != null) if (menu != null)
{ {

@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
namespace AOLBackend.Controllers.Usuarios namespace AOLBackend.Controllers.Usuarios
{ {
[Route("api/[controller]")] [Route("api/Catalogos/[controller]")]
[ApiController] [ApiController]
public class UsuariosController : ControllerBase public class UsuariosController : ControllerBase
{ {
@ -28,9 +28,9 @@ namespace AOLBackend.Controllers.Usuarios
catch (Exception ex) { return StatusCode(500, ex.Message); } catch (Exception ex) { return StatusCode(500, ex.Message); }
} }
[Route("getAllUsuarios")] [Route("GetAll")]
[HttpGet] [HttpGet]
public async Task<IActionResult> GetAllUsuarios() public async Task<IActionResult> GetAll()
{ {
try try
{ {
@ -102,7 +102,7 @@ namespace AOLBackend.Controllers.Usuarios
} }
[Route("createUser")] [Route("Append")]
[HttpPost] [HttpPost]
public async Task<IActionResult> POST(IUsuarios user) public async Task<IActionResult> POST(IUsuarios user)
{ {

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

@ -6,32 +6,8 @@
public string Usuario { get; set; } = null!; public string Usuario { get; set; } = null!;
public string Nombre { get; set; } = null!; public string Nombre { get; set; } = null!;
public string Contrasena { get; set; } = null!; public string Contrasena { get; set; } = null!;
public string Correo { get; set; } = null!;
public byte TipoUsuario { get; set; } = 2; public byte TipoUsuario { get; set; } = 2;
public byte Activo { get; set; } = 1; public byte Activo { get; set; } = 1;
public string FechaAlta { get; set; } = null!;
public int UsuarioAlta { get; set; } = 0!;
public string FechaModifico { get; set; } = null!;
public int UsuarioModifico { get; set; } = 0!;
public string FechaElimino { get; set; } = null!;
public int UsuarioElimino { get; set; } = 0!;
public string MotivoElimino { get; set; } = null!;
public int IdModulo { get; set; } = 0!;
public int Dept { get; set; } = 0!;
public string? sDept { get; set; } = null!;
public int Tmercancia { get; set; } = 0!;
public string FechaUltimaVisita { get; set; } = null!;
public int Visitas { get; set; } = 0!;
public int Internos { get; set; } = 0!;
public int PermisoEspecial { get; set; } = 0!;
public int EstadoConfiguracion { get; set; } = 0!;
public string FechaValidacionConf { get; set; } = null!;
public string RealizoEncuesta { get; set; } = null!;
public int EncuestaActiva { get; set; } = 0!;
public string FechaLimiteEncuesta { get; set; } = null!;
public string CodigoAccesoM { get; set; } = null!;
public string TokenAccesoM { set; get; } = null!;
public string DeviceToken { get; set; } = null!;
public int IdPerfil { get; set; } = 0!; public int IdPerfil { get; set; } = 0!;
} }
} }

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

@ -2,9 +2,13 @@ using AOLBackend.Context;
using AOLBackend.Contracts; using AOLBackend.Contracts;
using AOLBackend.Contracts.Catalogos; using AOLBackend.Contracts.Catalogos;
using AOLBackend.Contracts.Operaciones; using AOLBackend.Contracts.Operaciones;
using AOLBackend.Contracts.Utils;
using AOLBackend.Repository; using AOLBackend.Repository;
using AOLBackend.Repository.Catalogos; using AOLBackend.Repository.Catalogos;
using AOLBackend.Repository.Operaciones; using AOLBackend.Repository.Operaciones;
using AOLBackend.Repository.Utils;
using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using System.Text; using System.Text;
@ -25,6 +29,10 @@ builder.Services.AddScoped<ICatRutasRepository, CatRutasRepository>();
//Operaciones //Operaciones
builder.Services.AddScoped<IOpViajesRepository, OpViajesRepository>(); builder.Services.AddScoped<IOpViajesRepository, OpViajesRepository>();
//Utilerias
builder.Services.AddScoped<IFileManagerRepository, FileManagerRepository>();
builder.Services.AddScoped<IFilePaths4ProcessRepository, FilePaths4ProcessRepository>();
builder.Services.AddControllers(); builder.Services.AddControllers();
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{ {
@ -51,6 +59,7 @@ builder.Services.AddCors(p => p.AddPolicy("corsapp", builder =>
"http://localhost:7001", "http://localhost:7001",
"http://localhost:5000", "http://localhost:5000",
"https://localhost:5001", "https://localhost:5001",
"https://alphaomega.com.mx",
"https://www.alphaomega.com.mx", "https://www.alphaomega.com.mx",
"https://74.208.165.122", "https://74.208.165.122",
"https://www.alphaomega.com.mx:443", "https://www.alphaomega.com.mx:443",

@ -84,7 +84,7 @@ namespace AOLBackend.Repository
public async Task<DTOLogin> ResetPassword(DTOLogin user) public async Task<DTOLogin> ResetPassword(DTOLogin user)
{ {
var query = "resetPassword"; var query = "[Usuario.ResetPassword]";
using (var connection = _context.CreateConnection()) using (var connection = _context.CreateConnection())
{ {
var usuarios = await connection.QueryAsync<DTOLogin>(query, new var usuarios = await connection.QueryAsync<DTOLogin>(query, new
@ -101,7 +101,7 @@ namespace AOLBackend.Repository
public async Task<IUsuarios> CreateUsuario(IUsuarios user) public async Task<IUsuarios> CreateUsuario(IUsuarios user)
{ {
var query = "createUsuario"; var query = "[Usuario.Append]";
using (var connection = _context.CreateConnection()) using (var connection = _context.CreateConnection())
{ {
if (user.Id == 0) user.Contrasena = _config.GetValue<string>("DefaultUser:Password"); if (user.Id == 0) user.Contrasena = _config.GetValue<string>("DefaultUser:Password");
@ -111,11 +111,8 @@ namespace AOLBackend.Repository
@Usuario = user.Usuario, @Usuario = user.Usuario,
@Nombre = user.Nombre, @Nombre = user.Nombre,
@Contrasena = CryptDecrypt.Encrypt(user.Contrasena), @Contrasena = CryptDecrypt.Encrypt(user.Contrasena),
@Correo = user.Correo,
@TipoUsuario = user.TipoUsuario, @TipoUsuario = user.TipoUsuario,
@Activo = user.Activo, @Activo = user.Activo,
@UsuarioAlta = user.UsuarioAlta,
@IdPerfil = user.IdPerfil
}, commandType: CommandType.StoredProcedure); }, commandType: CommandType.StoredProcedure);
return usuario.First(); return usuario.First();
} }

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

@ -22,6 +22,8 @@
}, },
"EmailServer": "146.20.161.11", "EmailServer": "146.20.161.11",
"EmailPort": 587, "EmailPort": 587,
"Email": "noreply@alphaomega.com.mx",
"EmailPassword": "Al%G22a3",
"pathArchivoElectronico": "D:\\data\\ArchivoElectronicoSIR\\www.gemcousa.com\\SIR-GEMCO\\DOCS-SIR\\", "pathArchivoElectronico": "D:\\data\\ArchivoElectronicoSIR\\www.gemcousa.com\\SIR-GEMCO\\DOCS-SIR\\",
"pathTemp": "D:\\data\\temp\\", "pathTemp": "D:\\data\\temp\\",
"pathFotosBodega": "D:\\data\\Bodega\\Fotos\\", "pathFotosBodega": "D:\\data\\Bodega\\Fotos\\",

Binary file not shown.

Binary file not shown.

@ -1 +1 @@
eefe8f67b06397f0ffbb2eddb23dd69eb10fac57 543d6e2052e74dfe9cc3f60cc2cb0d6f72d7753c

Binary file not shown.

Binary file not shown.

@ -240,3 +240,66 @@
2.0 2.0
2.0 2.0
2.0 2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0
2.0

Loading…
Cancel
Save