public (string, string) GetPath(DependencyFileType dependencyType, int dependencyId) { var relativePath = $@"arquivos\{dependencyType.ToString().ToLower()}\{dependencyId.ToString()}"; var path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), relativePath); return(path, relativePath); }
public void SaveFiles(DependencyFileType dependencyType, int dependencyId, IFormFileCollection files) { (string path, string relativePath) = GetPath(dependencyType, dependencyId); Directory.CreateDirectory(path); List <Arquivo> arquivos = new List <Arquivo>(); foreach (var formFile in files) { if (formFile.Length > 0) { string file = GetFileName(path, formFile.FileName); using (var stream = new FileStream(file, FileMode.Create)) { formFile.CopyTo(stream); } arquivos.Add(new Arquivo { DataUpload = DateTime.Now, DependencyId = dependencyId, DependencyType = dependencyType, Nome = formFile.FileName, Tamanho = formFile.Length, Path = Path.Combine(relativePath, Path.GetFileName(file)), ContentType = formFile.ContentType }); } } _db.Arquivos.AddRange(arquivos); _db.SaveChanges(); }
public void ExcluiArquivos(DependencyFileType dependency, int id) { var arquivos = (_repositoryBase as IArquivoRepository).BuscaArquivos(dependency, id); foreach (var arquivo in arquivos) { Excluir(arquivo); } }
public Arquivo(string nome, long tamanho, string contentType, string emailUsuario, string nomeUsuario, DependencyFileType dependencyType, int dependencyId) { Nome = nome; Tamanho = tamanho; ContentType = contentType; EmailUsuario = emailUsuario; NomeUsuario = nomeUsuario; DependencyType = dependencyType; DependencyId = dependencyId; }
public async Task <Arquivo> SalvarArquivo(Stream file, DependencyFileType dependencyType, int dependencyId, string emailUsuario, string nomeUsuario, string nomeArquivo, string contentType) { var arquivosExistentes = _unitOfWork.ArquivoRepository.BuscaArquivos(dependencyType, dependencyId); if (arquivosExistentes.Any(a => a.Nome == nomeArquivo)) { throw new DuplicatedException("Já há um arquivo salvo com esse nome."); } var novoArquivo = new Arquivo( nomeArquivo, file.Length, contentType, emailUsuario, nomeUsuario, dependencyType, dependencyId ); var arquivoSalvo = await _unitOfWork.ArquivoRepository.Adicionar(novoArquivo, file); _unitOfWork.Commit(); return(arquivoSalvo); }
public void DeleteFiles(DependencyFileType dependency, int id) { Delete(a => a.DependencyId == id && a.DependencyType == dependency); }
public List <Arquivo> GetFiles(DependencyFileType dependency, int id) { return(Query(a => a.DependencyId == id && a.DependencyType == dependency).ToList()); }
public IEnumerable <Arquivo> BuscaArquivos(DependencyFileType dependency, int id) => (_repositoryBase as IArquivoRepository).BuscaArquivos(dependency, id);
private string GetRelativePath(DependencyFileType dependencyType, int dependencyId) { return($@"{dependencyType.ToString().ToLower()}/{dependencyId.ToString()}"); }
public IEnumerable <Arquivo> BuscaArquivos(DependencyFileType dependency, int id) => _db.Arquivos.Where(a => a.DependencyId == id && a.DependencyType == dependency);
/// <summary> /// Initializes a dependency file. /// </summary> /// <param name="filePath">File path.</param> /// <param name="fileType">File type.</param> public DependencyFile(string filePath, DependencyFileType fileType) { FilePath = filePath; FileType = fileType; }