protected void pagamentoButton_Click(object sender, EventArgs e) { try { string numPedido = pedidosDropDownList.SelectedValue; double totalPedido = ItensDao.ListarItensPorPedido(numPedido).Sum(p => p.ValorTotalItem); string cartao = cartaoTextBox.Text; ServiceProxy.PagamentoContract pagamento = new ServiceProxy.PagamentoContract(); pagamento.NumeroCartao = cartao; pagamento.NumeroPedido = numPedido; pagamento.Valor = totalPedido; ServiceProxy.ServicePagamentosClient service = new ServiceProxy.ServicePagamentosClient(); int resposta = service.EfetuarPagamento(pagamento); switch (resposta) { case 1: throw new Exception("Este cartão não existe"); case 2: throw new Exception("Este pedido já foi pago"); case 3: throw new Exception("Limite excedido"); } mensagemLabel.CssClass = "text text-success"; mensagemLabel.Text = "Pedido <strong>" + numPedido + "</strong> pago com sucesso"; } catch (Exception ex) { mensagemLabel.CssClass = "text text-danger"; mensagemLabel.Text = ex.Message; } }
protected void pagamentoButton_Click(object sender, EventArgs e) { try { //Obtendo o numero do pedido string numPedido = pedidoDropDowList.SelectedValue; //o valor total de itens para o pedido selecionado double totalPedido = ItensDao.ListarItensPorPedidos(numPedido).Sum(p => p.ValorTotalItem); //Obtendo o numero do cartao string cartao = cartaoTextBox.Text; //instanciando a classe pagamento contract obtida atrves do serviço ServiceProxy.PagamentoContract pagamento = new ServiceProxy.PagamentoContract(); pagamento.NumeroCartao = cartao; pagamento.NumeroPedido = numPedido; pagamento.Valor = totalPedido; ServiceProxy.ServicePagamentosClient service = new ServiceProxy.ServicePagamentosClient(); int resposta = service.EfetuarPagamento(pagamento); switch (resposta) { case 1: throw new Exception("Numero de cartão não encontrado"); case 2: throw new Exception("O pedido ja foi está pago"); case 3: throw new Exception("Limite insuficiente"); default: break; } mensagemLabel.CssClass = "text text-success"; mensagemLabel.Text = "Pedido <strong>" + numPedido + "</strong> pago com sucesso"; } catch (Exception ex) { mensagemLabel.CssClass = "text text-danger"; mensagemLabel.Text = ex.Message; } }
protected void pagamentoButton_Click(object sender, EventArgs e) { try { //obtendo o numero do pedido string numPedido = pedidosDropDownList.SelectedValue; //obtendo o total de itens para o pedido selecionado double totalPedido = ItensDao.ListarItensPorPedido(numPedido) .Sum(p => p.ValorTotalItem); //obtendo o numero do cartão string cartao = cartaoTextBox.Text; //instanciando a classe PagamentoContract obtida através //do serviço ServiceProxy.PagamentoContract pagamento = new ServiceProxy.PagamentoContract(); pagamento.NumeroCartao = cartao; pagamento.NumeroPedido = numPedido; pagamento.Valor = totalPedido; //instanciando a classe ServicePagamentoCliente, obtida //através do webservice ServiceProxy.ServicePagamentosClient service = new ServiceProxy.ServicePagamentosClient(); int resposta = service.EfetuarPagamento(pagamento); switch (resposta) { case 1: throw new Exception("Este cartão não existe"); case 2: throw new Exception("Este pedido já foi pago"); case 3: throw new Exception("Não há limite no cartão"); } mensagemLabel.CssClass = "text text-success"; mensagemLabel.Text = "Pedido <strong>" + numPedido + "</strong> pago com sucesso."; } catch (Exception ex) { mensagemLabel.CssClass = "text text-danger"; mensagemLabel.Text = ex.Message; } }