protected void BtnCadastro_Click(object sender, EventArgs e) { try { CorridasController actionCreateCorrida = new CorridasController(); Corridas corridas = new Corridas(); corridas.ValorCorrida = inputValor.Text; corridas.Origem = inputCidadeOrigem.Text; corridas.EstadoOrigem = selectUfOrigem.Value.ToString(); corridas.Destino = inputCidadeFinal.Text; corridas.EstadoDestino = selectUfFinal.Value.ToString(); corridas.IdMotorista = Convert.ToInt32(selectMotorista.Value.ToString()); corridas.IdPassageiro = Convert.ToInt32(selectPassageiro.Value.ToString()); actionCreateCorrida.Create(corridas); cleanCampos(); ClientScript.RegisterStartupScript(GetType(), "teste", "succesCadastro();", true); } catch (Exception ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CorridasController getMotoristasAndPassageiros = new CorridasController(); var tableMotoristas = getMotoristasAndPassageiros.getAllMotoristas(); var tablePassageiros = getMotoristasAndPassageiros.getAllPassageiros(); if (tableMotoristas != null) { var consulta = from motorista in tableMotoristas.AsEnumerable() select motorista; foreach (var dr in consulta) { string name = dr.Field <string>("FirstName") + " " + dr.Field <string>("LastName"); selectMotorista.Items.Add(new ListItem(name, dr.Field <int>("IdMotorista").ToString())); } } if (tablePassageiros != null) { var consulta = from passageiro in tablePassageiros.AsEnumerable() select passageiro; foreach (var dr in consulta) { string name = dr.Field <string>("FirstName") + " " + dr.Field <string>("LastName"); selectPassageiro.Items.Add(new ListItem(name, dr.Field <int>("IdPassageiro").ToString())); } } } }
public void getCorridas() { DataTable table = new DataTable(); CorridasController getCorrida = new CorridasController(); table = getCorrida.getAllCorridas(); if (table != null) { GridView1.DataSource = table; GridView1.DataBind(); } }