public async Task CarregaArquivos(CarregaArquivosDto arquivos) { if (arquivos.ProjetoId.Equals(Guid.Empty)) { throw new RegraDeNegocioException(MensagensSistema.IdDoProjetoNaoInformado); } if (string.IsNullOrEmpty(arquivos.Caminho)) { throw new RegraDeNegocioException(MensagensSistema.CaminhoInexistente); } if (!arquivos.Arquivos.Any()) { throw new RegraDeNegocioException(MensagensSistema.NenhumArquivoFoiSelecionado); } foreach (var arquivo in arquivos.Arquivos) { if (arquivo.Length <= 0) { continue; } var stream = new MemoryStream(); await arquivo.CopyToAsync(stream); await Cadastrar(new ArquivoDto(arquivos.Caminho, arquivo.FileName, arquivos.ProjetoId, stream)); } }
public async Task <IActionResult> CadastrarArquivos([FromForm] CarregaArquivosDto arquivos) { try { await _arquivosServico.CarregaArquivos(arquivos); return(StatusCode(201, MensagensSistema.ArquivosCadastradosComSucesso)); } catch (RegraDeNegocioException e) { var guid = Guid.NewGuid(); return(BadRequest(new ResultadoOperacao(false, MensagensSistema.Erro500RegraNegocio + e.Message, guid))); } catch (Exception) { var guid = Guid.NewGuid(); return(BadRequest(new ResultadoOperacao(false, MensagensSistema.Erro500 + guid.ToString(), guid))); } }