Ejemplo n.º 1
0
        public async Task <string> AdicionarImagemPassagem(HistoricoDePassagem historico, Stream arquivo)
        {
            try
            {
                if (historico != null)
                {
                    var caminho     = historico.Arquivo;
                    var caminhoBlob = $"fotos";

                    this._servicoExternoDePersistencia.Persistir();
                    await this._servicoExternoDeArmazenamentoEmNuvem.EnviarArquivoAsync(arquivo, caminhoBlob, caminho);

                    this._servicoExternoDePersistencia.Persistir();
                }

                this._servicoExternoDePersistencia.Persistir();


                return("Fotos adicionadas com sucesso");
            }

            catch (ExcecaoDeAplicacao ex)
            {
                throw new ExcecaoDeAplicacao(ex.Message);
            }

            catch (Exception ex)
            {
                throw new ExcecaoDeAplicacao(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task <string> AdicionarHistoricoPassagem(ModeloDeEdicaoDeCarater modelo, UsuarioLogado usuario, HttpPostedFileBase imagem)
        {
            DateTime dataHoraFato = new DateTime();
            var      carater      = this._servicoExternoDePersistencia.RepositorioDeCaraters.PegarPorId(modelo.Id);
            var      usuarioBanco = this._servicoExternoDePersistencia.RepositorioDeUsuarios.BuscarPorId(usuario.Id);

            if (!string.IsNullOrEmpty(modelo.DataHistorico) && !string.IsNullOrEmpty(modelo.HoraHistorico))
            {
                var data = Convert.ToDateTime(modelo.DataHistorico);
                var hora = Convert.ToDateTime(modelo.HoraHistorico);
                dataHoraFato = new DateTime(data.Year, data.Month, data.Day, hora.Hour, hora.Minute, 0);
            }

            var historicoPassagem = new HistoricoDePassagem(dataHoraFato, modelo.DescricaoHistorico, carater.Veiculo != null ? carater.Veiculo.Placa : String.Empty, String.Empty, modelo.Latitude, modelo.Longitude);

            carater.AdicionarHistoricoPassagem(historicoPassagem, usuarioBanco);

            if (imagem != null)
            {
                int      MaxContentLength      = 1024 * 1024 * 3; //3 MB
                string[] AllowedFileExtensions = new string[] { ".jpg", ".png" };
                var      extensao = imagem.FileName.Substring(imagem.FileName.LastIndexOf('.'));

                if (!AllowedFileExtensions.Contains(imagem.FileName.Substring(imagem.FileName.LastIndexOf('.'))))
                {
                    throw new ExcecaoDeAplicacao("Extensão não permitida. Favor enviar somente: '.jpg', '.png'.");
                }

                if (imagem.ContentLength > MaxContentLength)
                {
                    throw new ExcecaoDeAplicacao("Permitido enviar no máximo 3mb.");
                }

                var caminho     = _servicoDeGeracaoDeHashSha.GerarParaStream(imagem.InputStream) + extensao;
                var caminhoBlob = $"fotos";

                historicoPassagem.Arquivo = caminho;
                this._servicoExternoDePersistencia.Persistir();

                try
                {
                    imagem.InputStream.Position = 0;
                    await this._servicoExternoDeArmazenamentoEmNuvem.EnviarArquivoAsync(imagem.InputStream, caminhoBlob, caminho);
                } catch (Exception ex)
                {
                    throw new ExcecaoDeAplicacao("Não foi possível salvar o arquivo:" + ex.InnerException);
                }
            }

            this._servicoExternoDePersistencia.Persistir();

            return("Histórico cadastrado com sucesso.");
        }
Ejemplo n.º 3
0
        public ModeloDeHistoricoDePassagensDaLista(HistoricoDePassagem historico, bool ehCelular, Camera camera = null)
        {
            if (historico == null)
            {
                return;
            }

            this.Id           = historico.Id;
            this.DataPassagem = historico.Data.ToString("dd/MM/yyyy HH:mm");
            this.Local        = historico.Local;

            var arquivoTratado = historico.Arquivo.Replace(@"I:\", "").Replace(@"\", @"/");
            var caminho        = VariaveisDeAmbiente.Pegar <string>("LOCAL:servidorDePassagens") + arquivoTratado;

            if (ehCelular)
            {
                caminho.Replace("https://", "http://");
            }
            if (historico.TipoDeHistoricoDePassagem == TipoDeHistoricoDePassagem.Automatico)
            {
                this.Arquivo = caminho;
            }
            else if (historico.TipoDeHistoricoDePassagem == TipoDeHistoricoDePassagem.Manual)
            {
                if (!String.IsNullOrEmpty(historico.Arquivo))
                {
                    var caminhoBlob = $"{VariaveisDeAmbiente.Pegar<string>("azure:caminhoDoBlob")}fotos/{historico.Arquivo}";
                    this.Arquivo = caminhoBlob;
                }
            }
            else if (!String.IsNullOrEmpty(historico.Arquivo))
            {
                this.Arquivo = caminho;
            }

            if (camera != null)
            {
                this.TemLatLong    = true;
                this.Cidade        = camera.Cidade.Descricao;
                this.Latitude      = camera.Latitude;
                this.Longitude     = camera.Longitude;
                this.LocalParaMapa = $"<b>{camera.Cidade.Descricao}</b><br/>{historico.Local}";
            }
            else
            {
                this.TemLatLong    = !String.IsNullOrEmpty(historico.Latitude) && !String.IsNullOrEmpty(historico.Longitude) ? true : false;
                this.Latitude      = historico.Latitude;
                this.Longitude     = historico.Longitude;
                this.LocalParaMapa = $"{historico.Local}";
            }

            this.IdCarater = historico.Carater != null ? historico.Carater.Id : 0;
        }
Ejemplo n.º 4
0
        public ModeloDeHistoricoDePassagensDaLista(HistoricoDePassagem historico, List <Camera> cameras)
        {
            if (historico == null)
            {
                return;
            }

            if (cameras != null)
            {
                var camera = cameras.FirstOrDefault(a => a.Nome == historico.Local);
                if (camera != null)
                {
                    this.TemLatLong    = true;
                    this.Cidade        = camera.Cidade.Descricao;
                    this.Latitude      = camera.Latitude;
                    this.Longitude     = camera.Longitude;
                    this.LocalParaMapa = $"<b>{camera.Cidade.Descricao}</b><br/>{historico.Local}";
                }
                else
                {
                    this.TemLatLong = !String.IsNullOrEmpty(historico.Latitude) && !String.IsNullOrEmpty(historico.Longitude) ? true : false;
                    this.Latitude   = historico.Latitude;
                    this.Longitude  = historico.Longitude;
                    this.Cidade     = historico.Carater.Cidade != null ? historico.Carater.Cidade.Descricao : String.Empty;
                }
            }

            this.Id            = historico.Id;
            this.DataPassagem  = historico.Data.ToString("dd/MM/yyyy HH:mm");
            this.Local         = historico.Local;
            this.TipoHistorico = historico.TipoDeHistoricoDePassagem.ToString();
            if (historico.Carater != null)
            {
                this.IdCarater = historico.Carater != null ? historico.Carater.Id : 0;
                this.Placa     = historico.Carater.Veiculo != null ? historico.Carater.Veiculo.Placa : String.Empty;
            }
        }