Beispiel #1
0
        /// <summary>
        /// Realiza o upload de um arquivo
        /// </summary>
        private async Task <string> RealizarUploadAnexo(DateTime dataLancamento, CadastrarAnexoEntrada cadastroEntrada)
        {
            if (_googleDriveUtil.Invalido)
            {
                this.AdicionarNotificacoes(_googleDriveUtil.Notificacoes);
                return(null);
            }

            // Pasta referente ao ano do lançamento
            var pastaAno = await _googleDriveUtil.CriarPasta(dataLancamento.Year.ToString(), ID_PASTA_GOOGLE_DRIVE);

            // Pasta referente ao mês do lançamento
            var pastaMes = await _googleDriveUtil.CriarPasta(dataLancamento.Month.ToString(), pastaAno.Id);

            // Verifica se um arquivo com o mesmo nome já existe na pasta do mês do lançamento
            var anexoJaExistente = await _googleDriveUtil.ProcurarPorNome(GoogleDriveUtil.TipoGoogleDriveFile.Arquivo, cadastroEntrada.NomeArquivo, pastaMes.Id);

            this.NotificarSeNaoNulo(anexoJaExistente, AnexoMensagem.Nome_Arquivo_Ja_Existe_Google_Drive);

            if (this.Invalido)
            {
                return(null);
            }

            // Realiza o upload do arquivo
            return(await _googleDriveUtil.RealizarUpload(cadastroEntrada.NomeArquivo, cadastroEntrada.MimeTypeArquivo, cadastroEntrada.ConteudoArquivo, cadastroEntrada.Descricao, pastaMes.Id));

            //await _googleDriveUtil.ExcluirPorNome(GoogleDriveUtil.TipoGoogleDriveFile.Pasta, dataLancamento.Year.ToString());
        }
        public async Task <ISaida> CadastrarAnexo(CadastrarAnexoEntrada cadastroEntrada)
        {
            // Verifica se as informações para cadastro foram informadas corretamente
            if (cadastroEntrada.Invalido)
            {
                return(new Saida(false, cadastroEntrada.Mensagens, null));
            }

            var lancamento = await _lancamentoRepositorio.ObterPorId(cadastroEntrada.IdLancamento);

            // Verifica se o lançamento existe
            this.NotificarSeNulo(lancamento, LancamentoMensagem.Id_Lancamento_Nao_Existe);

            if (this.Invalido)
            {
                return(new Saida(false, this.Mensagens, null));
            }

            // Insere as informações do anexo no banco de dados e realiza o upload do arquivo para o Google Drive
            var anexo = await _anexoRepositorio.Inserir(lancamento.Data, cadastroEntrada);

            if (_anexoRepositorio.Invalido)
            {
                return(new Saida(false, _anexoRepositorio.Mensagens, null));
            }

            await _uow.Commit();

            return(_uow.Invalido
                ? new Saida(false, _uow.Mensagens, null)
                : new Saida(true, new[] { AnexoMensagem.Anexo_Cadastrado_Com_Sucesso }, new AnexoSaida(anexo)));
        }
Beispiel #3
0
        public Anexo(CadastrarAnexoEntrada cadastrarEntrada, string idGoogleDrive)
        {
            if (cadastrarEntrada.Invalido)
            {
                return;
            }

            this.IdLancamento  = cadastrarEntrada.IdLancamento;
            this.IdGoogleDrive = idGoogleDrive;
            this.Descricao     = cadastrarEntrada.Descricao;
            this.NomeArquivo   = cadastrarEntrada.NomeArquivo;
        }
Beispiel #4
0
        public async Task <Anexo> Inserir(DateTime dataLancamento, CadastrarAnexoEntrada cadastroEntrada)
        {
            // Realiza o upload do arquivo do anexo para o Google Drive
            var idGoogleDrive = await RealizarUploadAnexo(dataLancamento, cadastroEntrada);

            if (this.Invalido)
            {
                return(null);
            }

            var anexo = new Anexo(cadastroEntrada, idGoogleDrive);

            await _efContext.AddAsync(anexo);

            return(anexo);
        }
        public async Task <ISaida> CadastrarAnexo([FromForm, SwaggerParameter("Informações de cadastro do anexo.", Required = true)] CadastrarAnexoViewModel model)
        {
            CadastrarAnexoEntrada cadastrarEntrada;

            using (var memoryStream = new MemoryStream())
            {
                await model.Arquivo.CopyToAsync(memoryStream);

                cadastrarEntrada = new CadastrarAnexoEntrada(
                    base.ObterIdUsuarioClaim(),
                    model.IdLancamento.Value,
                    model.Descricao,
                    model.NomeArquivo + model.Arquivo.FileName.Substring(model.Arquivo.FileName.LastIndexOf(".")),
                    memoryStream.ToArray(),
                    model.Arquivo.ContentType);
            }

            return(await _lancamentoServico.CadastrarAnexo(cadastrarEntrada));
        }