diff --git a/.vs/AOLBackend/DesignTimeBuild/.dtbcache.v2 b/.vs/AOLBackend/DesignTimeBuild/.dtbcache.v2 index fec5692..cc1a271 100644 Binary files a/.vs/AOLBackend/DesignTimeBuild/.dtbcache.v2 and b/.vs/AOLBackend/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/AOLBackend/v17/.futdcache.v1 b/.vs/AOLBackend/v17/.futdcache.v1 index c224f0a..36bf145 100644 Binary files a/.vs/AOLBackend/v17/.futdcache.v1 and b/.vs/AOLBackend/v17/.futdcache.v1 differ diff --git a/.vs/AOLBackend/v17/.suo b/.vs/AOLBackend/v17/.suo index 3837fc1..f8c5c57 100644 Binary files a/.vs/AOLBackend/v17/.suo and b/.vs/AOLBackend/v17/.suo differ diff --git a/.vs/ProjectEvaluation/aolbackend.metadata.v2 b/.vs/ProjectEvaluation/aolbackend.metadata.v2 index 5a05f1c..5edb00a 100644 Binary files a/.vs/ProjectEvaluation/aolbackend.metadata.v2 and b/.vs/ProjectEvaluation/aolbackend.metadata.v2 differ diff --git a/.vs/ProjectEvaluation/aolbackend.projects.v2 b/.vs/ProjectEvaluation/aolbackend.projects.v2 index b1f8eda..7e37f8b 100644 Binary files a/.vs/ProjectEvaluation/aolbackend.projects.v2 and b/.vs/ProjectEvaluation/aolbackend.projects.v2 differ diff --git a/Contracts/Utils/IFileManagerRepository.cs b/Contracts/Utils/IFileManagerRepository.cs new file mode 100644 index 0000000..dbe4765 --- /dev/null +++ b/Contracts/Utils/IFileManagerRepository.cs @@ -0,0 +1,12 @@ +using AOLBackend.Models.Utils; +namespace AOLBackend.Contracts.Utils +{ + public interface IFileManagerRepository + { + public Task FileManager(FileManager data); + public Task getFileByProcess(long id, int Proceso); + public Task> getAllFilesByProcess(long Tags, int Proceso); + public Task getFileById(long id); + public Task deleteFileByProcess(long id, int Proceso); + } +} \ No newline at end of file diff --git a/Contracts/Utils/IFilePaths4ProcessRepository.cs b/Contracts/Utils/IFilePaths4ProcessRepository.cs new file mode 100644 index 0000000..eec9bc7 --- /dev/null +++ b/Contracts/Utils/IFilePaths4ProcessRepository.cs @@ -0,0 +1,9 @@ +using AOLBackend.Models.Utils; + +namespace AOLBackend.Contracts.Utils +{ + public interface IFilePaths4ProcessRepository + { + public Task getPaths4ProcessById(long id); + } +} \ No newline at end of file diff --git a/Controllers/Usuarios/AuthController.cs b/Controllers/Usuarios/AuthController.cs index 6ea438c..ac7e0f4 100644 --- a/Controllers/Usuarios/AuthController.cs +++ b/Controllers/Usuarios/AuthController.cs @@ -48,7 +48,6 @@ namespace AOLBackend.Controllers.Usuarios claims.Add(new Claim(JwtRegisteredClaimNames.Iat, DateTime.UtcNow.ToString())); claims.Add(new Claim("UserId", user.Id.ToString())); 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")); if (menu != null) { diff --git a/Controllers/Usuarios/UsuariosController.cs b/Controllers/Usuarios/UsuariosController.cs index 5835189..760c7ed 100644 --- a/Controllers/Usuarios/UsuariosController.cs +++ b/Controllers/Usuarios/UsuariosController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc; namespace AOLBackend.Controllers.Usuarios { - [Route("api/[controller]")] + [Route("api/Catalogos/[controller]")] [ApiController] public class UsuariosController : ControllerBase { @@ -28,9 +28,9 @@ namespace AOLBackend.Controllers.Usuarios catch (Exception ex) { return StatusCode(500, ex.Message); } } - [Route("getAllUsuarios")] + [Route("GetAll")] [HttpGet] - public async Task GetAllUsuarios() + public async Task GetAll() { try { @@ -102,7 +102,7 @@ namespace AOLBackend.Controllers.Usuarios } - [Route("createUser")] + [Route("Append")] [HttpPost] public async Task POST(IUsuarios user) { diff --git a/Controllers/Utils/FileManagerController.cs b/Controllers/Utils/FileManagerController.cs new file mode 100644 index 0000000..e52fabe --- /dev/null +++ b/Controllers/Utils/FileManagerController.cs @@ -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("AllFiles"); + } + + [Route("GetFileInfoByProcess")] + [HttpGet] + public async Task GetFileInfoByProcess([FromQuery] int id, int Proceso) + { + FileManager data = new FileManager(); + data = await _Repo.getFileByProcess(id, Proceso); + return data; + } + + [Route("GetFileInfoById")] + [HttpGet] + public async Task GetFileInfoByProcess([FromQuery] int id) + { + FileManager data = new FileManager(); + data = await _Repo.getFileById(id); + return data; + } + + [Route("AppendFileByProcess")] + [HttpPost] + public async Task 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 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 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" }); + } + + + } +} \ No newline at end of file diff --git a/Controllers/Utils/MFileManagerController.cs b/Controllers/Utils/MFileManagerController.cs new file mode 100644 index 0000000..24ea000 --- /dev/null +++ b/Controllers/Utils/MFileManagerController.cs @@ -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("AllFiles"); + } + + [HttpGet] + [Route("GetFilesFromLog")] + public async Task> 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 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> Append(List FileList, int Tags, int Proceso, int Usuario) + { + List data = new List(); + FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); + SvcMFileManager FM = new SvcMFileManager(_config, _Repo, RootPath + RelativePath.Path); + List filePaths = await FM.SaveFile2DiskList(FileList); + var fileData = await FM.SaveFileLog(filePaths, Tags, Proceso, Usuario); + return fileData; + } + } +} \ No newline at end of file diff --git a/Models/IUsuarios.cs b/Models/IUsuarios.cs index 61cf899..c5eb4ab 100644 --- a/Models/IUsuarios.cs +++ b/Models/IUsuarios.cs @@ -6,32 +6,8 @@ public string Usuario { get; set; } = null!; public string Nombre { get; set; } = null!; public string Contrasena { get; set; } = null!; - public string Correo { get; set; } = null!; public byte TipoUsuario { get; set; } = 2; 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!; } } diff --git a/Models/Utils/FileManager.cs b/Models/Utils/FileManager.cs new file mode 100644 index 0000000..29e363b --- /dev/null +++ b/Models/Utils/FileManager.cs @@ -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!; + } +} \ No newline at end of file diff --git a/Models/Utils/FilePaths4Process.cs b/Models/Utils/FilePaths4Process.cs new file mode 100644 index 0000000..59cbc3b --- /dev/null +++ b/Models/Utils/FilePaths4Process.cs @@ -0,0 +1,7 @@ +namespace AOLBackend.Models.Utils +{ + public class FilePaths4Process + { + public string Path { set; get; } = string.Empty; + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 751eac1..3a76e3a 100644 --- a/Program.cs +++ b/Program.cs @@ -2,9 +2,13 @@ using AOLBackend.Context; using AOLBackend.Contracts; using AOLBackend.Contracts.Catalogos; using AOLBackend.Contracts.Operaciones; +using AOLBackend.Contracts.Utils; + using AOLBackend.Repository; using AOLBackend.Repository.Catalogos; using AOLBackend.Repository.Operaciones; +using AOLBackend.Repository.Utils; + using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; using System.Text; @@ -25,6 +29,10 @@ builder.Services.AddScoped(); //Operaciones builder.Services.AddScoped(); +//Utilerias +builder.Services.AddScoped(); +builder.Services.AddScoped(); + builder.Services.AddControllers(); builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { @@ -51,6 +59,7 @@ builder.Services.AddCors(p => p.AddPolicy("corsapp", builder => "http://localhost:7001", "http://localhost:5000", "https://localhost:5001", + "https://alphaomega.com.mx", "https://www.alphaomega.com.mx", "https://74.208.165.122", "https://www.alphaomega.com.mx:443", diff --git a/Repository/UsuariosRepository.cs b/Repository/UsuariosRepository.cs index bba5a97..bfb6a51 100644 --- a/Repository/UsuariosRepository.cs +++ b/Repository/UsuariosRepository.cs @@ -84,7 +84,7 @@ namespace AOLBackend.Repository public async Task ResetPassword(DTOLogin user) { - var query = "resetPassword"; + var query = "[Usuario.ResetPassword]"; using (var connection = _context.CreateConnection()) { var usuarios = await connection.QueryAsync(query, new @@ -101,7 +101,7 @@ namespace AOLBackend.Repository public async Task CreateUsuario(IUsuarios user) { - var query = "createUsuario"; + var query = "[Usuario.Append]"; using (var connection = _context.CreateConnection()) { if (user.Id == 0) user.Contrasena = _config.GetValue("DefaultUser:Password"); @@ -111,11 +111,8 @@ namespace AOLBackend.Repository @Usuario = user.Usuario, @Nombre = user.Nombre, @Contrasena = CryptDecrypt.Encrypt(user.Contrasena), - @Correo = user.Correo, @TipoUsuario = user.TipoUsuario, @Activo = user.Activo, - @UsuarioAlta = user.UsuarioAlta, - @IdPerfil = user.IdPerfil }, commandType: CommandType.StoredProcedure); return usuario.First(); } diff --git a/Repository/Utils/FileManagerRepository.cs b/Repository/Utils/FileManagerRepository.cs new file mode 100644 index 0000000..9d4e3cf --- /dev/null +++ b/Repository/Utils/FileManagerRepository.cs @@ -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 data) + { + var query = "[Utils.FileManager.Append]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(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 getFileByProcess(long id, int Proceso) + { + var query = "[Utils.FileManager.Get]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(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 getFileById(long id) + { + var query = "[Utils.FileManager.Get]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(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> getAllFilesByProcess(long Tags, int Proceso) + { + var query = "[Utils.FileManager.Get]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(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(query, new + { + @id = id, + @Proceso = Proceso, + }, + commandType: CommandType.StoredProcedure); + } + } +} \ No newline at end of file diff --git a/Repository/Utils/FilePaths4ProcessRepository.cs b/Repository/Utils/FilePaths4ProcessRepository.cs new file mode 100644 index 0000000..e64b572 --- /dev/null +++ b/Repository/Utils/FilePaths4ProcessRepository.cs @@ -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 getPaths4ProcessById(long id) + { + var query = "[Utils.FileManager.RootPath.Get]"; + using var connection = _context.CreateConnection(); + var entrada = await connection.QueryAsync(query, new + { + @id = id, + }, + commandType: CommandType.StoredProcedure); + return entrada.First(); + } + } +} \ No newline at end of file diff --git a/Services/EmailSender/EmailSender.cs b/Services/EmailSender/EmailSender.cs new file mode 100644 index 0000000..fef392f --- /dev/null +++ b/Services/EmailSender/EmailSender.cs @@ -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("DefaultUser:Password"); + string emailServer = _config.GetValue("EmailServer"); + int emailPort = _config.GetValue("EmailPort"); + htmlContent = (htmlContent.Length > 0) ? htmlContent : $@" + + + + + + + + + + + + +
Hola: {toUser.Nombre}, mediante el siguiente correo electronico, se le notifica que se le ha creado un nuevo acceso
Para acceder a su cuenta, favor de entrar a: http://reportes.gemcousa.com/
Nombre de usuario: {toUser.Usuario}
Contraseña: {defaultPassword}
Su contraseña inicial sera: {defaultPassword}, pero es necesario que la cambie antes de poder ingresar
Para cambiar la contraseña, puede ir al menu Reset, proporcione su nombre de usuario y su nueva contraseña
Si por alguna razon, no recuerda su contrasena, repita este proceso de resetear su contraseña
No es necesario responder a este correo, ya que fue generado en automatico por el sistema.
Nota: Las credenciales de acceso son responsabilidad personal, nadie solo usted debe conocerlas
Que tenga un excelente dia!
+ + "; + try + { + using (var smtp = new SmtpClient(emailServer, emailPort)) + { + smtp.Credentials = new NetworkCredential(_config.GetValue("Email"), _config.GetValue("EmailPassword")); + var correo = new MailMessage(); + correo.From = new MailAddress(_config.GetValue("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; + } + } + } +} \ No newline at end of file diff --git a/Services/MFileManager/SvcMFileManager.cs b/Services/MFileManager/SvcMFileManager.cs new file mode 100644 index 0000000..d997a7f --- /dev/null +++ b/Services/MFileManager/SvcMFileManager.cs @@ -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> GetFilesFromLog(int Tags, int Proceso) + { + return await _Repo.getAllFilesByProcess(Tags, Proceso); + } + + public async Task 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> SaveFile2DiskList(List FileList) + { + DateTime time = DateTime.Now; + var filePaths = new List(); + 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> SaveFileLog(List files, int Tags, int Proceso, int Usuario) + { + List resultados = new List(); + 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); + } + } +} diff --git a/appsettings.json b/appsettings.json index 5072260..22a9fd1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -22,6 +22,8 @@ }, "EmailServer": "146.20.161.11", "EmailPort": 587, + "Email": "noreply@alphaomega.com.mx", + "EmailPassword": "Al%G22a3", "pathArchivoElectronico": "D:\\data\\ArchivoElectronicoSIR\\www.gemcousa.com\\SIR-GEMCO\\DOCS-SIR\\", "pathTemp": "D:\\data\\temp\\", "pathFotosBodega": "D:\\data\\Bodega\\Fotos\\", diff --git a/bin/Debug/net6.0/AOLBackend.dll b/bin/Debug/net6.0/AOLBackend.dll index 2cc4298..19a5452 100644 Binary files a/bin/Debug/net6.0/AOLBackend.dll and b/bin/Debug/net6.0/AOLBackend.dll differ diff --git a/bin/Debug/net6.0/AOLBackend.pdb b/bin/Debug/net6.0/AOLBackend.pdb index 7d3df47..1d852bd 100644 Binary files a/bin/Debug/net6.0/AOLBackend.pdb and b/bin/Debug/net6.0/AOLBackend.pdb differ diff --git a/obj/Debug/net6.0/AOLBackend.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/AOLBackend.csproj.CoreCompileInputs.cache index 5d32c31..809d404 100644 --- a/obj/Debug/net6.0/AOLBackend.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/AOLBackend.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -eefe8f67b06397f0ffbb2eddb23dd69eb10fac57 +543d6e2052e74dfe9cc3f60cc2cb0d6f72d7753c diff --git a/obj/Debug/net6.0/AOLBackend.dll b/obj/Debug/net6.0/AOLBackend.dll index 2cc4298..19a5452 100644 Binary files a/obj/Debug/net6.0/AOLBackend.dll and b/obj/Debug/net6.0/AOLBackend.dll differ diff --git a/obj/Debug/net6.0/AOLBackend.pdb b/obj/Debug/net6.0/AOLBackend.pdb index 7d3df47..1d852bd 100644 Binary files a/obj/Debug/net6.0/AOLBackend.pdb and b/obj/Debug/net6.0/AOLBackend.pdb differ diff --git a/obj/Debug/net6.0/ref/AOLBackend.dll b/obj/Debug/net6.0/ref/AOLBackend.dll index 537b9bb..12e88de 100644 Binary files a/obj/Debug/net6.0/ref/AOLBackend.dll and b/obj/Debug/net6.0/ref/AOLBackend.dll differ diff --git a/obj/Debug/net6.0/refint/AOLBackend.dll b/obj/Debug/net6.0/refint/AOLBackend.dll index 537b9bb..12e88de 100644 Binary files a/obj/Debug/net6.0/refint/AOLBackend.dll and b/obj/Debug/net6.0/refint/AOLBackend.dll differ diff --git a/obj/staticwebassets.pack.sentinel b/obj/staticwebassets.pack.sentinel index 2f43a0a..a812a0f 100644 --- a/obj/staticwebassets.pack.sentinel +++ b/obj/staticwebassets.pack.sentinel @@ -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