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)); }
public ActionResult ExcluirDemanda(long idDemanda) { PontoEntrega pontoEntrega_bd = UnitOfWork.PontoEntregaRepository.Get(p => p.IdPontoEntrega == idDemanda && p.DataExclusao == null).FirstOrDefault(); VaosDemandaPoste vaosDemandaPoste_bd = UnitOfWork.VaosDemandaPosteRepository.Get(v => v.IdPontoEntrega == idDemanda && pontoEntrega_bd.DataExclusao == null).FirstOrDefault(); if (vaosDemandaPoste_bd != null) { vaosDemandaPoste_bd.DataExclusao = DateTime.Now; UnitOfWork.VaosDemandaPosteRepository.Update(vaosDemandaPoste_bd); UnitOfWork.Save(); } if (pontoEntrega_bd != null) { pontoEntrega_bd.DataExclusao = DateTime.Now; UnitOfWork.PontoEntregaRepository.Update(pontoEntrega_bd); UnitOfWork.Save(); return(Json(new ResponseView() { Status = Status.OK, Result = Resources.Messages.Save_OK }, JsonRequestBehavior.AllowGet)); } else { return(Json(new ResponseView() { Status = Status.NotFound, Result = Resources.Messages.Poste_Not_Found }, JsonRequestBehavior.AllowGet)); } }
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)); } }
public ActionResult SalvarPontoEntregaNovo(PontoEntregaView PontoEntregaReceived) { Cidade Cidade = UnitOfWork.CidadeRepository.Get(c => c.IdCidade == PontoEntregaReceived.IdCidade).FirstOrDefault(); if (Cidade != null) { double latPonto = Double.Parse(PontoEntregaReceived.LatitudeTexto, System.Globalization.CultureInfo.InvariantCulture); double lonPonto = Double.Parse(PontoEntregaReceived.LongitudeTexto, System.Globalization.CultureInfo.InvariantCulture); //double latPoste = Double.Parse(PontoEntregaReceived.LatitudePosteTexto, System.Globalization.CultureInfo.InvariantCulture); // double lonPoste = Double.Parse(PontoEntregaReceived.LongitudePosteTexto, System.Globalization.CultureInfo.InvariantCulture); OrdemDeServico ordemServico = UnitOfWork.OrdemDeServicoRepository.Get(or => or.NumeroOS == PontoEntregaReceived.IdOrdemServicoTexto).FirstOrDefault(); ConverterLatLonToUtm converter = new ConverterLatLonToUtm(Cidade.Datum, Cidade.NorteOuSul, Cidade.Zona); UTM utmPonto = converter.Convert(latPonto, lonPonto); // UTM utmPoste = converter.Convert(latPoste, lonPoste); PontoEntrega new_ponto_entrega = new PontoEntrega(); new_ponto_entrega.IdCidade = PontoEntregaReceived.IdCidade; new_ponto_entrega.IdPoste = PontoEntregaReceived.IdPoste; new_ponto_entrega.CodigoGeoBD = PontoEntregaReceived.CodigoGeoBD; new_ponto_entrega.Complemento1 = PontoEntregaReceived.Complemento1; // 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 = utmPonto.X; new_ponto_entrega.Y = utmPonto.Y; new_ponto_entrega.IdOrdemDeServico = ordemServico.IdOrdemDeServico; new_ponto_entrega.DataInclusao = DateTime.Now; new_ponto_entrega.Classificacao = PontoEntregaReceived.Classificacao; new_ponto_entrega.Ocorrencia = PontoEntregaReceived.Ocorrencia; new_ponto_entrega.QtdDomicilio = PontoEntregaReceived.QtdDomicilio; new_ponto_entrega.QtdSalas = PontoEntregaReceived.QtdDomicilioComercio; new_ponto_entrega.NumeroAndaresEdificio = PontoEntregaReceived.NumeroAndaresEdificio; new_ponto_entrega.TotalApartamentosEdificio = PontoEntregaReceived.TotalApartamentosEdificio; new_ponto_entrega.NomeEdificio = PontoEntregaReceived.NomeEdificio; new_ponto_entrega.QtdBlocos = PontoEntregaReceived.QtdBlocos; new_ponto_entrega.TipoComercio = PontoEntregaReceived.ClassificacaoComercio; /// 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); * }*/ UnitOfWork.Save(); PontoEntrega pontoEntrega = UnitOfWork.PontoEntregaRepository.Get(p => p.IdPontoEntrega == new_ponto_entrega.IdPontoEntrega).FirstOrDefault(); Poste Poste = UnitOfWork.PosteRepository.Get(p => p.IdPoste == PontoEntregaReceived.IdPoste).FirstOrDefault(); if (Poste != null) { VaosDemandaPoste vaosDemandaPoste = new VaosDemandaPoste { IdCidade = PontoEntregaReceived.IdCidade, IdOrdemDeServico = ordemServico.IdOrdemDeServico, IdPoste = PontoEntregaReceived.IdPoste, IdPontoEntrega = new_ponto_entrega.IdPontoEntrega, X1 = Poste.X, Y1 = Poste.Y, X2 = utmPonto.X, Y2 = utmPonto.Y, }; UnitOfWork.VaosDemandaPosteRepository.Insert(vaosDemandaPoste); UnitOfWork.Save(); VaosDemandaPoste VaosDemandaPoste = UnitOfWork.VaosDemandaPosteRepository.Get(v => v.IdVaosDemandaPoste == vaosDemandaPoste.IdVaosDemandaPoste).FirstOrDefault(); // return Json(new MetodosPontoEntregaView().PontoEntregaToPontoEntregaView(PontoEntrega), JsonRequestBehavior.AllowGet); return(Json(new { Demanda = new MetodosPontoEntregaView().PontoEntregaToPontoEntregaView(pontoEntrega), VaoDemandaPoste = new VaosDemandasPaginadoView().VaoToVaoView(VaosDemandaPoste) }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { Demanda = new MetodosPontoEntregaView().PontoEntregaToPontoEntregaView(pontoEntrega) }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new ResponseView() { Status = Status.NotFound, Result = "Cidade nao encontrada" }, JsonRequestBehavior.AllowGet)); } }
public PontoEntregaView PontoEntregaToPontoEntregaView(PontoEntrega ponto_entrega_bd) { // Poste poste = UnitOfWork.PosteRepository.Get(p => p.IdPoste == ponto_entrega_bd.IdPoste).FirstOrDefault(); Cidade cidade = UnitOfWork.CidadeRepository.Get(c => c.IdCidade == ponto_entrega_bd.IdCidade).FirstOrDefault(); ConverterUtmToLatLon converter = new ConverterUtmToLatLon(cidade.Datum, cidade.NorteOuSul, cidade.Zona); LatLon LatiLong = converter.Convert(ponto_entrega_bd.X, ponto_entrega_bd.Y); PontoEntregaView ponto_view = new PontoEntregaView(); ponto_view.IdPontoEntrega = ponto_entrega_bd.IdPontoEntrega; ponto_view.IdPoste = ponto_entrega_bd.IdPoste; ponto_view.CodigoGeoBD = ponto_entrega_bd.CodigoGeoBD; ponto_view.Complemento1 = ponto_entrega_bd.Complemento1; ponto_view.Complemento2 = ponto_entrega_bd.Complemento2; //ponto_view.Status = ponto_entrega_bd.Status; //ponto_view.ClasseAtendimento = ponto_entrega_bd.ClasseAtendimento; //ponto_view.TipoConstrucao = ponto_entrega_bd.TipoConstrucao; ponto_view.Numero = ponto_entrega_bd.Numero; ponto_view.ClasseSocial = ponto_entrega_bd.ClasseSocial; //ponto_view.Logradouro = ponto_entrega_bd.Logradouro; //ponto_view.Fase = ponto_entrega_bd.Fase; //ponto_view.EtLigacao = ponto_entrega_bd.EtLigacao; //ponto_view.Observacao = ponto_entrega_bd.Observacao; ponto_view.Latitude = LatiLong.Lat; ponto_view.Longitude = LatiLong.Lon; ponto_view.Classificacao = ponto_entrega_bd.Classificacao; ponto_view.ClassificacaoComercio = ponto_entrega_bd.TipoComercio; ponto_view.NomeEdificio = ponto_entrega_bd.NomeEdificio; ponto_view.NumeroAndaresEdificio = ponto_entrega_bd.NumeroAndaresEdificio; ponto_view.Ocorrencia = ponto_entrega_bd.Ocorrencia; ponto_view.QtdBlocos = ponto_entrega_bd.QtdBlocos; ponto_view.QtdDomicilio = ponto_entrega_bd.QtdDomicilio; ponto_view.QtdDomicilioComercio = ponto_entrega_bd.QtdSalas; ponto_view.TotalApartamentosEdificio = ponto_entrega_bd.TotalApartamentosEdificio; // Nova regra de Status do poste para a View string ImgAux = string.Empty; if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.COMERCIAL_P || ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.COMERCIAL_M || ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.COMERCIAL_G) { ImgAux = "comercio"; } else if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.EDIFÍCIO_RES || ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.EDIFICIO_EMPRESA || ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.EDIFICIO_COM || ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.EDIFÍCIO_CONSTRUCAO) { ImgAux = "predio"; } else if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.RESIDENCIAL) { ImgAux = "casa"; } else if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.TERRENO) { ImgAux = "terreno"; } else if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.COMERCIO_RESIDENCIA) { ImgAux = "misto"; } else if (ponto_view.ClasseSocial == BLL.Enums.ClasseSocial.VILA) { ImgAux = "vila"; } else { ImgAux = "duvida"; } ponto_view.Img = ImgAux; return(ponto_view); }