Handling related data Asp.net and C #

2

I'm developing an ASP.NET application, which aims to register events and add clients to these registered events, forming a list of clients for each event.

My question is this: In the Events table there are three types of input (integer type - because it saves the amount of input available for such an event), which are Courtesy, Bonus and Vip. So far so good. When I'm adding a new client for a particular event, I need to select the type of entry for it on a radio button. Whenever I add a client, I need the amount of the Event input type to decrease 1.
What I'm not getting is retrieving the value of the input type selected on the radiobutton to do the manipulation of the data.

NOTE: In the form to include client I select in a dropdownlist the desired event. I do not know if they need this information or if I can retrieve the values for each type of entry.

It seems to be simple, but as I'm at the beginning, I caught up at this point.

protected void btnIncluir_Click(object sender, EventArgs e)
{
    var db = new TheOneWebEntities();
    var cliente = new Cliente();
    cliente.Nome = tbNome.Text;
    cliente.Cpf = tbCpf.Text;
    cliente.Email = tbEmail.Text;
    cliente.Telefone = tbTelefone.Text;
    cliente.EventoId = Convert.ToInt32(ddlEvento.SelectedValue);

    int totalEntrada;

    if (rbCortesia.Checked)
    {
        if (evento.Cortesia <= 0)
        {
            Util.Alertar("Cortesia esgotada");
        }
        else
        {
            totalEntrada = cliente.Evento.Cortesia - 1;
            cliente.Evento.Cortesia = totalEntrada;
        }
    }
    else
    {
        if (rbBonus.Checked)
        {
            if (evento.Bonus <= 0)
            {
                Util.Alertar("Bônus esgotado");
            }
            else
            {
                totalEntrada = cliente.Evento.Bonus - 1;
                cliente.Evento.Bonus = totalEntrada;
            }
        }
        else
        {
            if (rbVip.Checked)
            {
                if (evento.Vip <= 0)
                {
                    Util.Alertar("VIP esgotado");
                }
                else
                {
                    totalEntrada = cliente.Evento.Vip - 1;
                    cliente.Evento.Vip = totalEntrada;
                }
            }
        }
    }
    var dataCadastro = DateTime.Now.ToString();
    cliente.DataCadastro = Convert.ToDateTime(dataCadastro);
    cliente.UsuarioId = WebMatrix.WebData.WebSecurity.CurrentUserId;

    db.Clientes.Add(cliente);
    db.SaveChanges();
    Util.Alertar("Cliente adicionado com sucesso!");
    Response.Redirect("~/User/MeusClientes.aspx");
}
    
asked by anonymous 03.08.2014 / 16:52

2 answers

3

Just complementing the Gypsy's answer

Create the RadioButtonList like this:

        <asp:RadioButtonList ID="rdgTipoEntrada" runat="server">
            <asp:ListItem Value="Cortesia">Cortesia</asp:ListItem>
            <asp:ListItem Value="Bonus">Bônus</asp:ListItem>
            <asp:ListItem Value="VIP">Vip</asp:ListItem>
        </asp:RadioButtonList>

CodeBehind

switch (rdgTipoEntrada.SelectedValue)
        {
            case "Cortesia":

                if (evento.Cortesia <= 0)
                {
                    Util.Alertar("Cortesia esgotada");
                }
                else
                {
                    totalEntrada = cliente.Evento.Cortesia - 1;
                    cliente.Evento.Cortesia = totalEntrada;
                }

                break;
            case "Bonus":

                if (evento.Bonus <= 0)
                {
                    Util.Alertar("Bônus esgotado");
                }
                else
                {
                    totalEntrada = cliente.Evento.Bonus - 1;
                    cliente.Evento.Bonus = totalEntrada;
                }

                break;
            case "VIP":

                if (rbVip.Checked)
                {
                    if (evento.Vip <= 0)
                    {
                        Util.Alertar("VIP esgotado");
                    }
                    else
                    {
                        totalEntrada = cliente.Evento.Vip - 1;
                        cliente.Evento.Vip = totalEntrada;
                    }
                }


                break;

        }
    
03.09.2014 / 06:39
2

If it's a RadioButtonList , I think it's easier to check the value with RadioButtonList itself:

switch (rdgTipoEntrada.SelectedItem.Value.ToString())
{
    case "Cortesia":
       ...
    case "Bônus":
       ...
    case "VIP":
       ...
}
    
04.08.2014 / 04:40