Ejemplo n.º 1
0
        public ActionResult GetPontoEntregaById(long idPontoEntrega)
        {
            PontoEntrega     pontoEntrega = UnitOfWork.PontoEntregaRepository.Get(p => p.IdPontoEntrega == idPontoEntrega && p.DataExclusao == null, includeProperties: "Cidade").FirstOrDefault();
            FotoPontoEntrega foto         = UnitOfWork.FotoPontoEntregaRepository.Get(f => f.IdPontoEntrega == idPontoEntrega && f.DataExclusao == null).FirstOrDefault();

            PontoEntregaView pontoEntregaView = new MetodosPontoEntregaView().PontoEntregaToPontoEntregaView(pontoEntrega);

            LatLon LatLong = new ConverterUtmToLatLon(pontoEntrega.Cidade.Datum, pontoEntrega.Cidade.NorteOuSul, pontoEntrega.Cidade.Zona).Convert(pontoEntrega.X, pontoEntrega.Y);

            //Object poste_return = new
            //{
            //    IdPoste = poste.IdPoste,
            //    Latitude = LatLong.Lat,
            //    Longitude = LatLong.Lon,
            //    //Img = poste.Finalizado == true ? "03" : "08",
            //    Img = poste.Finalizado == true ? "10" : "08",
            //    IdCidade = poste.IdCidade,
            //    CodGeo = poste.CodigoGeo,
            //    Altura = poste.Altura,
            //    TipoPoste = poste.TipoPoste,
            //    Esforco = poste.Esforco,
            //    Descricao = poste.Descricao
            //};

            return(Json(pontoEntregaView, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
        public void GetFoto(long IdFoto, int Width, int Height)
        {
            FotoPontoEntrega foto = UnitOfWork.FotoPontoEntregaRepository.Get(f => f.IdFotoPontoEntrega == IdFoto).FirstOrDefault();

            if (foto != null && System.IO.File.Exists(foto.Path))
            {
                new WebImage(foto.Path).Resize(Width, Height).Write();
            }
            else
            {
                new WebImage("~/Images/no-image-available.png").Resize(Width, Height).Write();
            }
        }
Ejemplo n.º 3
0
        public ActionResult SalvarPontoEntrega(PontoEntregaView PontoEntregaReceived)
        {
            if (PontoEntregaReceived != null)
            {
                //Poste poste = UnitOfWork.PosteRepository.Get(p => p.IdPoste == PontoEntregaReceived.IdPoste).FirstOrDefault();
                Cidade cidade = UnitOfWork.CidadeRepository.Get(c => c.IdCidade == PontoEntregaReceived.IdCidade).FirstOrDefault();

                ConverterLatLonToUtm converter = new ConverterLatLonToUtm(cidade.Datum, cidade.NorteOuSul, cidade.Zona);
                UTM utm = converter.Convert(PontoEntregaReceived.Latitude, PontoEntregaReceived.Longitude);

                if (PontoEntregaReceived.IdPontoEntrega != -1)
                {
                    #region Atualiza Ponto de Entrega

                    PontoEntrega ponto_entrega_bd = UnitOfWork.PontoEntregaRepository.Get(p => p.IdPontoEntrega == PontoEntregaReceived.IdPontoEntrega).FirstOrDefault();

                    // ponto_entrega_bd.IdPontoEntrega = PontoEntregaReceived.IdPontoEntrega;
                    //ponto_entrega_bd.IdPoste = PontoEntregaReceived.IdPoste;
                    ponto_entrega_bd.CodigoGeoBD = PontoEntregaReceived.CodigoGeoBD;
                    //   ponto_entrega_bd.IdOrdemDeServico = PontoEntregaReceived.IdOrdemServico;

                    ponto_entrega_bd.Classificacao = PontoEntregaReceived.Classificacao;
                    ponto_entrega_bd.Complemento1  = PontoEntregaReceived.Complemento1;
                    //ponto_entrega_bd.Complemento2 = PontoEntregaReceived.Complemento2;

                    //ponto_entrega_bd.Status = PontoEntregaReceived.Status;
                    // ponto_entrega_bd.ClasseAtendimento = PontoEntregaReceived.ClasseAtendimento;
                    //ponto_entrega_bd.TipoConstrucao = PontoEntregaReceived.TipoConstrucao;
                    ponto_entrega_bd.Numero       = PontoEntregaReceived.Numero;
                    ponto_entrega_bd.ClasseSocial = PontoEntregaReceived.ClasseSocial;
                    ponto_entrega_bd.IdLagradouro = PontoEntregaReceived.IdLogradouro;

                    ponto_entrega_bd.Classificacao             = PontoEntregaReceived.Classificacao;
                    ponto_entrega_bd.Ocorrencia                = PontoEntregaReceived.Ocorrencia;
                    ponto_entrega_bd.QtdDomicilio              = PontoEntregaReceived.QtdDomicilio;
                    ponto_entrega_bd.NumeroAndaresEdificio     = PontoEntregaReceived.NumeroAndaresEdificio;
                    ponto_entrega_bd.TotalApartamentosEdificio = PontoEntregaReceived.TotalApartamentosEdificio;
                    ponto_entrega_bd.NomeEdificio              = PontoEntregaReceived.NomeEdificio;
                    ponto_entrega_bd.QtdBlocos    = PontoEntregaReceived.QtdBlocos;
                    ponto_entrega_bd.TipoComercio = PontoEntregaReceived.ClassificacaoComercio;
                    ponto_entrega_bd.QtdSalas     = PontoEntregaReceived.QtdDomicilioComercio;
                    //ponto_entrega_bd.Fase = PontoEntregaReceived.Fase;
                    //ponto_entrega_bd.EtLigacao = PontoEntregaReceived.EtLigacao;
                    // ponto_entrega_bd.Observacao = PontoEntregaReceived.Observacao;
                    //ponto_entrega_bd.X = utm.X;
                    // ponto_entrega_bd.Y = utm.Y;

                    /// Atualizando o Ponto Entrega
                    UnitOfWork.PontoEntregaRepository.Update(ponto_entrega_bd);

                    List <Medidor> medidores_ponto_entrega = UnitOfWork.MedidoresRepository.Get(m => m.IdPontoEntrega == PontoEntregaReceived.IdPontoEntrega).ToList();

                    /// Apagando os Medidores do Ponto de Entrega
                    foreach (Medidor medidor_bd in medidores_ponto_entrega)
                    {
                        UnitOfWork.MedidoresRepository.Delete(medidor_bd);
                    }

                    /* if (PontoEntregaReceived.Medidores != null)
                     * {
                     *   foreach (MedidorView medidor_view in PontoEntregaReceived.Medidores)
                     *   {
                     *       /// Inserindo os Medidores
                     *       UnitOfWork.MedidoresRepository.Insert(new Medidor
                     *       {
                     *           IdPontoEntrega = medidor_view.IdPontoEntrega,
                     *           NumeroMedidor = medidor_view.NumeroMedidor,
                     *           ComplementoResidencial = medidor_view.ComplementoResidencial
                     *       });
                     *   }
                     * }*/

                    /// Apagando Fotos do ponto de Entrega
                    List <FotoPontoEntrega> fotos_BD = UnitOfWork.FotoPontoEntregaRepository.Get(p => p.IdPontoEntrega == PontoEntregaReceived.IdPontoEntrega).ToList();

                    foreach (FotoPontoEntrega foto_bd in fotos_BD)
                    {
                        UnitOfWork.FotoPontoEntregaRepository.Delete(foto_bd);
                    }

                    if (PontoEntregaReceived.Fotos != null)
                    {
                        foreach (FotoPontoEntregaView foto in PontoEntregaReceived.Fotos)
                        {
                            /// Nao deve Vim foto_view.DataFoto vazio mas se vim nao quebra o codigo
                            DateTime DataDiretorio = foto.DataFoto != String.Empty ? Convert.ToDateTime(foto.DataFoto) : DateTime.Now;
                            String   Data          = DataDiretorio.ToString("ddMMyyyy");

                            UnitOfWork.FotoPontoEntregaRepository.Insert(
                                new FotoPontoEntrega()
                            {
                                CodigoGeoBD    = -1,
                                DataFoto       = Convert.ToDateTime(foto.DataFoto),
                                IdPontoEntrega = PontoEntregaReceived.IdPontoEntrega,
                                NumeroFoto     = foto.NumeroFoto.Trim(),
                                DataExclusao   = null,
                                Path           = string.Format(ConfigurationManager.AppSettings["NewPathFotos"], cidade.CidadeDiretorio, Data, User.Identity.Name.ToUpper(), foto.NumeroFoto.Trim().ToUpper())
                            });
                        }
                    }


                    //Salvando as Alteraçoes
                    UnitOfWork.Save();


                    #endregion
                }
                else
                {
                    #region Novo Ponto de Entrega

                    PontoEntrega new_ponto_entrega = new PontoEntrega();

                    new_ponto_entrega.IdPoste     = PontoEntregaReceived.IdPoste;
                    new_ponto_entrega.CodigoGeoBD = PontoEntregaReceived.CodigoGeoBD;
                    // new_ponto_entrega.Status = PontoEntregaReceived.Status;
                    // new_ponto_entrega.ClasseAtendimento = PontoEntregaReceived.ClasseAtendimento;
                    // new_ponto_entrega.TipoConstrucao = PontoEntregaReceived.TipoConstrucao;
                    new_ponto_entrega.Numero       = PontoEntregaReceived.Numero;
                    new_ponto_entrega.ClasseSocial = PontoEntregaReceived.ClasseSocial;
                    // new_ponto_entrega.Logradouro = PontoEntregaReceived.Logradouro;
                    // new_ponto_entrega.Fase = PontoEntregaReceived.Fase;
                    // new_ponto_entrega.EtLigacao = PontoEntregaReceived.EtLigacao;
                    // new_ponto_entrega.Observacao = PontoEntregaReceived.Observacao;
                    new_ponto_entrega.X = utm.X;
                    new_ponto_entrega.Y = utm.Y;

                    /// Atualizando o Ponto Entrega
                    UnitOfWork.PontoEntregaRepository.Insert(new_ponto_entrega);

                    /*  if (PontoEntregaReceived.Medidores != null)
                     * {
                     *    foreach (MedidorView medidor_view in PontoEntregaReceived.Medidores)
                     *    {
                     *        /// Inserindo os Medidores
                     *        UnitOfWork.MedidoresRepository.Insert(new Medidor
                     *        {
                     *            IdPontoEntrega = new_ponto_entrega.IdPontoEntrega,
                     *            NumeroMedidor = medidor_view.NumeroMedidor,
                     *            ComplementoResidencial = medidor_view.ComplementoResidencial
                     *        });
                     *    }
                     * }*/

                    foreach (FotoPontoEntregaView foto in PontoEntregaReceived.Fotos)
                    {
                        /// Nao deve Vim foto_view.DataFoto vazio mas se vim nao quebra o codigo
                        DateTime DataDiretorio = foto.DataFoto != String.Empty ? Convert.ToDateTime(foto.DataFoto) : DateTime.Now;
                        String   Data          = DataDiretorio.ToString("ddMMyyyy");

                        FotoPontoEntrega novaFoto = new FotoPontoEntrega();
                        novaFoto.CodigoGeoBD    = -1;
                        novaFoto.DataFoto       = Convert.ToDateTime(foto.DataFoto);
                        novaFoto.IdPontoEntrega = new_ponto_entrega.IdPontoEntrega;
                        novaFoto.NumeroFoto     = foto.NumeroFoto.Trim();
                        novaFoto.DataExclusao   = null;
                        novaFoto.Path           = string.Format(ConfigurationManager.AppSettings["NewPathFotos"], cidade.CidadeDiretorio, Data, User.Identity.Name.ToUpper(), foto.NumeroFoto.Trim().ToUpper());
                        novaFoto.PontoEntrega   = new_ponto_entrega;

                        UnitOfWork.FotoPontoEntregaRepository.Insert(novaFoto);
                    }

                    //Salvando as Alteraçoes
                    UnitOfWork.Save();

                    #endregion
                }

                return(Json(new ResponseView()
                {
                    Status = Status.OK, Result = Resources.Messages.Save_OK
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new ResponseView()
                {
                    Status = Status.NOK, Result = Resources.Messages.Error_Save_Changes
                }, JsonRequestBehavior.AllowGet));
            }
        }