|
|
|
@ -7,6 +7,7 @@ using CORRESPONSALBackend.Contracts.Utils; |
|
|
|
|
using CORRESPONSALBackend.Models.Utils; |
|
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
|
|
using Microsoft.AspNetCore.Http.HttpResults; |
|
|
|
|
|
|
|
|
|
namespace CORRESPONSALBackend.Controllers |
|
|
|
|
{ |
|
|
|
@ -57,41 +58,46 @@ namespace CORRESPONSALBackend.Controllers |
|
|
|
|
|
|
|
|
|
[Route("AppendFileByProcess")] |
|
|
|
|
[HttpPost] |
|
|
|
|
public async Task<FileManager> AppendFileByProcess(IFormFile file, int IdUsuario, int Proceso, string Tags, int crud) |
|
|
|
|
public async Task<dynamic> 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.LastIndexOf('.') + 1); |
|
|
|
|
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) |
|
|
|
|
try{ |
|
|
|
|
DateTime time = DateTime.Now; |
|
|
|
|
FilePaths4Process RelativePath = await _RepoRelativePath.getPaths4ProcessById(Proceso); |
|
|
|
|
string fullPath = ""; |
|
|
|
|
fullPath = RootPathCorresponsales + RelativePath.Path; |
|
|
|
|
string fileMime = file.FileName.Substring(file.FileName.LastIndexOf('.') + 1); |
|
|
|
|
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) |
|
|
|
|
{ |
|
|
|
|
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) |
|
|
|
|
if (file.Length > 0) |
|
|
|
|
{ |
|
|
|
|
return await _Repo.FileManager(data); |
|
|
|
|
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; |
|
|
|
|
}catch(Exception ex){ |
|
|
|
|
return Ok(ex.Message); |
|
|
|
|
} |
|
|
|
|
return data; |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|