public string InsertOrUpdate(EnderecoView obj) { conn.Open(); var trans = conn.BeginTransaction(); try { EnderecoDao EnderecoDao = new EnderecoDao(conn, trans); obj = ValidarEstruturaEndereco(obj, trans); if (EnderecoDao.GetAsExist(obj.IdEndereco)) { EnderecoDao.Update(PopularParametrosEndereco(obj)); } else { EnderecoDao.Insert(PopularParametrosEndereco(obj)); } trans.Commit(); return("Sucesso"); } catch (Exception e) { trans.Rollback(); return(e.Message); } finally { conn.Close(); } }
private bool ValidarAlteracao(EnderecoView endereco, EnderecoView exit) { if (endereco.Bairro != exit.Bairro) { return(false); } if (endereco.IdCidade != exit.IdCidade) { return(false); } if (endereco.IdEstado != exit.IdEstado) { return(false); } if (endereco.Cep.Trim() != exit.Cep.Trim()) { return(false); } if (endereco.Logradouro.ToUpper() != exit.Logradouro.ToUpper()) { return(false); } if (endereco.Complemento.ToUpper() != exit.Complemento.ToUpper()) { return(false); } return(true); }
public IActionResult Deletar(int id, [FromServices] IUnitOfWork unitOfWork, bool interno = false) { try { if (id < 1) { return(new BadRequestObjectResult("Campo de Identificação Endereço Inválido")); } EnderecoView endereco = unitOfWork.EnderecoRepository().Get(id); if (string.IsNullOrWhiteSpace(endereco.Cep)) { return(new BadRequestObjectResult("Campo de Identificação Endereço Inválido")); } new EstadoService().Deletar(endereco.IdEstado, unitOfWork); new CidadeService().Deletar(endereco.IdCidade, unitOfWork); new BairroService().Deletar(endereco.IdCidade, unitOfWork); unitOfWork.EnderecoRepository().Remove(id); if (!interno) { unitOfWork.Commit(); } return(new OkResult()); } catch (Exception e) { unitOfWork.Rollback(); return(new BadRequestObjectResult(e.Message)); } }
private Estado PopularEstado(EnderecoView endereco) { return(new Estado { Id = endereco.IdEstado, Nome = endereco.NomeEstado, Uf = endereco.Uf }); }
private Cidade PopularCidade(EnderecoView enderecoView) { return(new Cidade { Id = enderecoView.IdCidade, Nome = enderecoView.Localidade, IdEstado = enderecoView.IdEstado }); }
private Bairro PopularBairro(EnderecoView enderecoView) { return(new Bairro { Id = enderecoView.IdBairro, Nome = enderecoView.Bairro, IdCidade = enderecoView.IdCidade }); }
private Cidade PopularParametrosCidade(EnderecoView obj) { Cidade cidade = new Cidade(); cidade.Id_Cidade = obj.IdCidade; cidade.Estado = obj.IdEstado; cidade.Nome = obj.Localidade; return(cidade); }
private Bairro PopularParametrosBairro(EnderecoView obj) { Bairro bairro = new Bairro(); bairro.Id_Bairro = obj.IdBairro; bairro.Cidade = obj.IdCidade; bairro.Nome = obj.Bairro; return(bairro); }
private Estado PopularParametrosEstado(EnderecoView obj) { Estado estado = new Estado(); estado.Id_Estado = obj.IdEstado; estado.Uf = obj.Uf; estado.Nome = obj.NomeEstado; return(estado); }
private Endereco PopularEndereco(EnderecoView enderecoView) { return(new Endereco { Id = enderecoView.IdEndereco, IdEstado = enderecoView.IdEstado, IdCidade = enderecoView.IdCidade, IdBairro = enderecoView.IdBairro, Logradouro = enderecoView.Logradouro, Complemento = enderecoView.Complemento, Cep = enderecoView.Cep }); }
private Endereco PopularParametrosEndereco(EnderecoView obj) { Endereco endereco = new Endereco(); endereco.Id_Endereco = obj.IdEndereco; endereco.Id_Estado = obj.IdEstado; endereco.Id_Cidade = obj.IdCidade; endereco.Id_Bairro = obj.IdBairro; endereco.Logradouro = obj.Logradouro; endereco.Complemento = obj.Complemento; endereco.Cep = obj.Cep; return(endereco); }
/// <summary> /// Metodo para validar se Possui Estado , Cidade e Bairro /// </summary> /// <param name="obj"></param> /// <param name="trans"></param> /// <returns></returns> public EnderecoView ValidarEstruturaEndereco(EnderecoView obj, SqlTransaction trans) { new EstadoService().InsertOrUpdate(PopularParametrosEstado(obj), trans, conn); obj.IdEstado = new EstadoDao(conn, trans).GetAsObject(new Estado { Nome = obj.NomeEstado, Uf = obj.Uf }).Id_Estado; new CidadeService().InsertOrUpdate(PopularParametrosCidade(obj), trans, conn); obj.IdCidade = new CidadeDao(conn, trans).GetAsObject(new Cidade { Nome = obj.Localidade, Estado = obj.IdEstado }).Id_Cidade; new BairroService().InsertOrUpdate(PopularParametrosBairro(obj), trans, conn); obj.IdBairro = new BairroDao(conn, trans).GetAsObject(new Bairro { Nome = obj.Bairro, Cidade = obj.IdCidade }).Id_Bairro; return(obj); }
public List <EnderecoView> EnderecosList() { List <EnderecoView> listaEndereco = new List <EnderecoView>(); StringBuilder sqlSelect = new StringBuilder(); sqlSelect.Append(@"SELECT E.Id_Endereco , E.Cep , E.Id_Estado , ES.Uf , ES.Nome AS NomeEstado , E.Id_Cidade , C.Nome AS NomeCidade , E.Id_Bairro , B.Nome AS NomeBairro , E.Logradouro , E.Complemento FROM dbo.Endereco E, dbo.Estado ES, dbo.Cidade C, dbo.Bairro B WHERE E.Id_Estado = ES.Id_Estado AND E.Id_Estado = C.Id_Estado AND E.id_Cidade = C.Id_Cidade AND E.Id_Bairro = B.Id_Bairro AND E.id_Cidade = B.Id_Cidade"); SqlCommand cmd = new SqlCommand(sqlSelect.ToString(), _conn); cmd.Transaction = _trans; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { EnderecoView endereco = PopularObjetoEnderecoView(reader); listaEndereco.Add(endereco); } } return(listaEndereco); }
public IActionResult Salvar(EnderecoView enderecoView, [FromServices] IUnitOfWork unitOfWork ) { try { if (string.IsNullOrWhiteSpace(enderecoView.Cep)) { return(new BadRequestObjectResult("Campo de Cep do Endereço Inválido")); } enderecoView.IdEstado = new EstadoService().Salvar(PopularEstado(enderecoView), unitOfWork); enderecoView.IdCidade = new CidadeService().Salvar(PopularCidade(enderecoView), unitOfWork); enderecoView.IdBairro = new BairroService().Salvar(PopularBairro(enderecoView), unitOfWork); EnderecoView exit = unitOfWork.EnderecoRepository().Get(enderecoView.IdEndereco); if (exit.IdEndereco > 0) { enderecoView.IdEndereco = exit.IdEndereco; if (!ValidarAlteracao(enderecoView, exit)) { unitOfWork.EnderecoRepository().Update(PopularEndereco(enderecoView)); } } else { unitOfWork.EnderecoRepository().Add(PopularEndereco(enderecoView)); } unitOfWork.Commit(); } catch (Exception e) { unitOfWork.Rollback(); return(new BadRequestObjectResult(e.Message)); } return(new OkObjectResult("Cadastrado Com Sucesso")); }
public void inicializarComponente() { _TituloLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.TITULO1], HorizontalTextAlignment = TextAlignment.Center }; _enderecoView = new EnderecoView { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, }; _enderecoView.SetBinding(EnderecoView.BindingContextProperty, new Binding(".")); _MetodoEntregaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO], LineBreakMode = LineBreakMode.TailTruncation }; _MetodoEntregaLabel.SetBinding(Label.TextProperty, new Binding("EntregaStr")); _FormaPagamentoLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO], LineBreakMode = LineBreakMode.TailTruncation }; _FormaPagamentoLabel.SetBinding(Label.TextProperty, new Binding("PagamentoStr")); _TrocoParaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _TrocoParaLabel.SetBinding(Label.TextProperty, new Binding("TrocoParaStr", stringFormat: "R${0}")); _ValorFreteLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _ValorFreteLabel.SetBinding(Label.TextProperty, new Binding("ValorFreteStr", stringFormat: "R${0}")); _ValorTotalLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _ValorTotalLabel.SetBinding(Label.TextProperty, new Binding("TotalStr", stringFormat: "R${0}")); _SituacaoLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, LineBreakMode = LineBreakMode.TailTruncation, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _SituacaoLabel.SetBinding(Label.TextProperty, new Binding("SituacaoStr")); _diaEntregaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _diaEntregaLabel.SetBinding(Label.TextProperty, new Binding("DiaEntregaStr")); _horarioEntregaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _horarioEntregaLabel.SetBinding(Label.TextProperty, new Binding("HorarioEntrega")); _mensagemRetiradaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _mensagemRetiradaLabel.SetBinding(Label.TextProperty, new Binding("Loja.MensagemRetirada")); _ObservacaoLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.LABEL_CAMPO] }; _ObservacaoLabel.SetBinding(Label.TextProperty, new Binding("Observacao")); _PedidoView = new PedidoView { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, }; _PedidoView.SetBinding(PedidoView.BindingContextProperty, new Binding(".")); _ImprimirButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.BTN_PRINCIPAL], Text = "Imprimir Boleto" }; _ImprimirButton.Clicked += async(sender, e) => { if (Pedido.Pagamento == null && !Pedido.IdPagamento.HasValue) { //UserDialogs.Instance.Alert("Pedido não possui pagamento vinculado.", "Erro", "Fechar"); await DisplayAlert("Erro", "Pedido não possui pagamento vinculado.", "Entendi"); return; } if (Pedido.Pagamento == null) { UserDialogs.Instance.ShowLoading("Carregando..."); try { var regraPagamento = PagamentoFactory.create(); var pagamento = await regraPagamento.pegar(Pedido.IdPagamento.Value); UserDialogs.Instance.HideLoading(); Pedido.Pagamento = pagamento; } catch (Exception erro) { UserDialogs.Instance.HideLoading(); //UserDialogs.Instance.Alert(erro.Message, "Erro", "Fechar"); await DisplayAlert("Erro", erro.Message, "Entendi"); } } var boletoImprimePage = new BoletoImprimePage { Pagamento = Pedido.Pagamento }; await Navigation.PushAsync(boletoImprimePage); }; _AcompanhaButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.BTN_SUCESSO], Text = "Acompanhar no Mapa" }; _AcompanhaButton.Clicked += acompanharClicked; _CancelarButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.BTN_DANGER], Text = "Cancelar" }; _CancelarButton.Clicked += cancelarClicked; _AvaliarButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.BTN_SUCESSO], Text = "Avaliar" }; _AvaliarButton.Clicked += avaliarClicked; _horarioButton = new Button { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, Style = Estilo.Current[Estilo.BTN_SUCESSO], Text = "Definir horário de entrega" }; _horarioButton.Clicked += horarioClicked; _empresaLabel = new Label { HorizontalOptions = LayoutOptions.Fill, VerticalOptions = LayoutOptions.Start, HorizontalTextAlignment = TextAlignment.Center, FontAttributes = FontAttributes.Bold, Margin = new Thickness(0, 0, 0, 3), Text = "Smart Tecnologia ®" }; _empresaLabel.SetBinding(Label.TextProperty, new Binding("Loja.Nome")); _rodapeLayout = new StackLayout { Orientation = StackOrientation.Vertical, VerticalOptions = LayoutOptions.End, HorizontalOptions = LayoutOptions.Fill, Margin = new Thickness(5, 0), Spacing = 0, Children = { new Label { VerticalOptions = LayoutOptions.Start, HorizontalOptions = LayoutOptions.Fill, HorizontalTextAlignment = TextAlignment.Center, Text = "Esse pedido foi feito em:", FontSize = 10 }, _empresaLabel } }; }
public IActionResult SaveEndereco(EnderecoView endereco, [FromServices] IUnitOfWork unitOfWork) { return(new EnderecoService().Salvar(endereco, unitOfWork)); }
public string InsertOrUpdate([FromBody] EnderecoView endereco) { return(new EnderecoService().InsertOrUpdate(endereco)); }