示例#1
0
        public ActionResult Create(EnderecoViewModel end)
        {
            if (ModelState.IsValid)
            {
                var addr = end.ToEndereco();

                var latlng = GeocodingService.obterCoordenadas(addr);
                addr.Latitude  = latlng.Latitude;
                addr.Longitude = latlng.Longitude;

                var addrId = _enderecoService.SalvarEndereco(addr);

                var estacao = new Estacao
                {
                    Endereco  = _enderecoService.ObterPorId(addrId),
                    Latitude  = latlng.Latitude,
                    Longitude = latlng.Longitude
                };

                _estacaoService.SalvarEstacao(estacao);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(end));
            }
        }
        public ActionResult Create(PacoteViewModel pacote)
        {
            if (ModelState.IsValid)
            {
                Pacote p = new Pacote
                {
                    TagRFID        = pacote.TagRfid,
                    DataPostagem   = DateTime.UtcNow,
                    Destinatario   = pacote.Destinatario,
                    DestinatarioId = Guid.Empty,
                    Codigo         = "",
                    Entregue       = false,
                    Rotas          = new List <Rota>(),
                    Conteudo       = new List <Item>(),
                    Remetente      = new Guid("ef849f5864534e3cadeba07a3cd9de94"),
                };

                if (pacote.Destino.Complemento == null)
                {
                    pacote.Destino.Complemento = "";
                }

                var addr = pacote.Destino.ToEndereco();

                var latlng = GeocodingService.obterCoordenadas(addr);
                addr.Latitude  = latlng.Latitude;
                addr.Longitude = latlng.Longitude;

                var addrId = _enderecoService.SalvarEndereco(addr);

                p.Destino = addrId;

                _pacoteService.SalvarPacote(p);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(pacote));
            }
        }