Esempio n. 1
0
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in gvToppings.Rows)
        {
            if (row.Cells[2].Text.ToLower().Equals(tbToppingName.Text.ToLower()))
            {
                if (!ClientScript.IsClientScriptBlockRegistered("script"))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language = 'javascript'>alert('Topping already exists')</script>");

                }
                return;
            }
        }

        if (tbToppingName.Text != String.Empty)
        {
            Topping topping = new Topping();
            topping.name = tbToppingName.Text;
            topping.active = "yes";

            using (MaryPizzaEntities ctx = new MaryPizzaEntities())
            {
                ctx.Toppings.Add(topping);
                ctx.SaveChanges();
                gvToppings.DataBind();
                if (!ClientScript.IsClientScriptBlockRegistered("script"))
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language = 'javascript'>alert('Topping successfully created!')</script>");

                }
            }
        }
    }
Esempio n. 2
0
    // The id parameter name should match the DataKeyNames value set on the control
    public void gvToppings_DeleteItem(int id)
    {
        using(MaryPizzaEntities ctx = new MaryPizzaEntities()){
            Topping topping = (from t in ctx.Toppings
                               where t.toppingId == id
                               select t).Single();

            topping.active = "no";
            ctx.SaveChanges();
        }
    }
Esempio n. 3
0
    protected void btnOrder_Click(object sender, EventArgs e)
    {
        string delivery;
        if (rbDelivery.Checked)
        {
            delivery = "Delivery";
        }
        else
        {
            delivery = "Pick Up";
        }

        using (MaryPizzaEntities ctx = new MaryPizzaEntities())
        {
            Order order = new Order();

            foreach (ListItem item in lbToppings.Items)
            {
                if (item.Selected)
                {
                    order.Toppings.Add(
                        ctx.Toppings.Where(t => t.name == item.Text).Select(t => t).First());
                }
            }

            order.delivery = delivery;
            order.firstname = tbFirst.Text;
            order.lastName = tbLast.Text;
            order.email = tbEmail.Text;
            order.phone = tbPhone.Text;
            order.size = ddlSize.SelectedValue;
            order.noOfPizzas = Int32.Parse(tbQuantity.Text);
            order.orderDate = DateTime.Now;
            ctx.Orders.Add(order);
            ctx.SaveChanges();

            if (!ClientScript.IsClientScriptBlockRegistered("script"))
            {
                String str = "Order Submitted!\\n"
                    + order.lastName + ", " + order.firstname + "\\n"
                    + "Phone: " + order.phone + "\\n"
                    + order.email + "\\n"
                    + "Size: " + order.size + "\\n"
                    + "Quantity: " + order.noOfPizzas + "\\n"
                    + order.email + "\\n"
                    + order.delivery + "\\n";

                ClientScript.RegisterStartupScript(this.GetType(), "script", "<script language = 'javascript'>if(confirm('" + str + "')){ window.location.href = 'Orders.aspx';} else {window.location.href = 'Orders.aspx';}</script>");
            }

        }
    }