Compare commits
No commits in common. 'ac52a8626275b632fbfb5f29d8b5feb75c65048f' and '701577deadd7d9e2a0011f8b091b95f3559a3b7f' have entirely different histories.
ac52a86262
...
701577dead
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,12 +0,0 @@ |
||||
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); |
||||
} |
||||
} |
@ -1,9 +0,0 @@ |
||||
using AOLBackend.Models.Utils; |
||||
|
||||
namespace AOLBackend.Contracts.Utils |
||||
{ |
||||
public interface IFilePaths4ProcessRepository |
||||
{ |
||||
public Task<FilePaths4Process> getPaths4ProcessById(long id); |
||||
} |
||||
} |
@ -1,148 +0,0 @@ |
||||
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" }); |
||||
} |
||||
|
||||
|
||||
} |
||||
} |
@ -1,56 +0,0 @@ |
||||
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; |
||||
} |
||||
} |
||||
} |
@ -1,10 +0,0 @@ |
||||
namespace AOLBackend.DTO.Usuario |
||||
{ |
||||
public class DTOUsuarioSendEmail |
||||
{ |
||||
public string Usuario { get; set; } = null!; |
||||
public string Nombre { get; set; } = null!; |
||||
public string Correo { get; set; } = null!; |
||||
|
||||
} |
||||
} |
@ -1,14 +0,0 @@ |
||||
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!; |
||||
} |
||||
} |
@ -1,7 +0,0 @@ |
||||
namespace AOLBackend.Models.Utils |
||||
{ |
||||
public class FilePaths4Process |
||||
{ |
||||
public string Path { set; get; } = string.Empty; |
||||
} |
||||
} |
@ -1,88 +0,0 @@ |
||||
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); |
||||
} |
||||
} |
||||
} |
@ -1,26 +0,0 @@ |
||||
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(); |
||||
} |
||||
} |
||||
} |
@ -1,61 +0,0 @@ |
||||
using System.Net.Mail; |
||||
using System.Net; |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Text; |
||||
//using EASendMail; |
||||
|
||||
namespace AOLBackend.Services.EmailSender |
||||
{ |
||||
public class EmailSender |
||||
{ |
||||
private IConfiguration _config; |
||||
|
||||
public EmailSender(IConfiguration config) |
||||
{ |
||||
_config = config; |
||||
} |
||||
public String SrvSendEmail(string htmlContent, string Subject, string toEmail) |
||||
{ |
||||
string EmailServer = _config.GetValue<string>("EmailServer"); |
||||
string EmailAccount = _config.GetValue<string>("EmailAccount"); |
||||
string[] Email = EmailAccount.Split('@'); |
||||
int EmailPort = Convert.ToInt32(_config.GetValue<string>("EmailPort")); |
||||
string EmailPassword = _config.GetValue<string>("EmailPassword"); |
||||
string EmailUser = Email[0]; |
||||
string EmailDomain = Email[1].Replace("@", ""); |
||||
DateTime now = DateTime.Now; |
||||
try |
||||
{ |
||||
using (var smtp = new SmtpClient(EmailServer, EmailPort)) |
||||
{ |
||||
smtp.UseDefaultCredentials = false; |
||||
smtp.Credentials = new NetworkCredential(EmailAccount, EmailPassword); |
||||
smtp.Host = EmailServer; |
||||
var correo = new MailMessage(EmailAccount, toEmail); |
||||
correo.From = new MailAddress("<" + EmailAccount + ">", "<" + EmailUser + ">"); |
||||
correo.Sender = new MailAddress("<" + EmailAccount + ">", "<" + EmailUser + ">"); |
||||
correo.Headers.Add("Message-Id", String.Concat("<", now.ToString("yyMMdd"), ".", now.ToString("HHmmss"), "@alphaomega.com.mx>")); |
||||
correo.To.Add(toEmail); |
||||
correo.Subject = Subject; |
||||
correo.Body = "htmlContent"; |
||||
correo.BodyEncoding = System.Text.Encoding.UTF8; |
||||
correo.SubjectEncoding = System.Text.Encoding.Default; |
||||
correo.IsBodyHtml = true; |
||||
smtp.Send(correo); |
||||
return "Message Sent Succesfully"; |
||||
} |
||||
} |
||||
catch (Exception ex) |
||||
{ |
||||
return ex.ToString(); |
||||
} |
||||
} |
||||
|
||||
|
||||
public String SrvSendEmail2(string htmlContent, string Subject, string toEmail) |
||||
{ |
||||
return ""; |
||||
} |
||||
} |
||||
} |
@ -1,106 +0,0 @@ |
||||
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@ |
||||
98dcc38fb2c7ab63ef7a47333e0e07fce2a8e400 |
||||
eefe8f67b06397f0ffbb2eddb23dd69eb10fac57 |
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue