Ejemplo n.º 1
0
        protected void lvCurrentOrders_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            using (DowntownDeliEntity dde = new DowntownDeliEntity())
            {
                switch (e.CommandName)
                {
                case "Complete":
                    ListViewDataItem item       = (ListViewDataItem)e.Item;
                    Label            lblOrderID = (Label)item.FindControl("lblOrderID");
                    int   id        = int.Parse(lblOrderID.Text);
                    Order RealOrder = dde.Orders.Find(id);
                    RealOrder.Complete = true;
                    dde.SaveChanges();
                    ListView lvCurrentOrders = (ListView)HeadLoginView.FindControl("lvCurrentOrders");
                    lvCurrentOrders.DataSource = dde.Orders.Include("Customer").Where(t => t.Complete == false || t.Complete == null).ToList();
                    lvCurrentOrders.DataBind();
                    break;

                case "Modify":
                    ListViewDataItem item2       = (ListViewDataItem)e.Item;
                    Label            lblOrderID2 = (Label)item2.FindControl("lblOrderID");
                    int   id2        = int.Parse(lblOrderID2.Text);
                    Order RealOrder2 = dde.Orders.Include("Product_Order").Where(t => t.Order_ID == id2).ToList().Single();
                    order       = RealOrder2;
                    ModifyOrder = true;
                    Response.Redirect("~/Pages/PlaceOrder.aspx", false);
                    break;
                }
            }
        }
Ejemplo n.º 2
0
 protected void Register_Click(object sender, EventArgs e)
 {
     using (DowntownDeliEntity dd = new DowntownDeliEntity())
     {
         Customer cust = dd.Customers.FirstOrDefault(a => a.Phone == Phone.Text);
         if (cust != null)
         {
             phoneUsed.Style["display"] = "block";
             return;
         }
         cust = dd.Customers.FirstOrDefault(a => a.Email == Username.Text);
         if (cust != null)
         {
             usernameUsed.Style["display"] = "block";
             return;
         }
         cust = new Customer();
         cust.Cust_Password = Password.Text;
         cust.Email         = Username.Text;
         cust.F_Name        = FirstName.Text;
         cust.L_Name        = LastName.Text;
         cust.Phone         = Phone.Text;
         dd.Customers.Add(cust);
         dd.SaveChanges();
         Server.Transfer("RegistrationComplete.aspx");
     }
 }
Ejemplo n.º 3
0
 protected void UpdateReward_Click(object sender, EventArgs e)
 {
     using (DowntownDeliEntity dd = new DowntownDeliEntity())
     {
         Customer cust = dd.Customers.First(a => a.Customer_ID == customer.Customer_ID);
         cust.Reward_CardID = reward.Text;
         dd.SaveChanges();
     }
     customer.Reward_CardID = reward.Text;
     Response.Redirect("LoggedIn.aspx");
 }
Ejemplo n.º 4
0
        protected void CheckOut_Click(object sender, EventArgs e)
        {
            using (DowntownDeliEntity dd = new DowntownDeliEntity())
            {
                decimal total = cart.Sum(a => a.Price);
                if (useRewardPoints)
                {
                    total = total - cart.OrderBy(a => a.Price).First().Price;
                    shoppingCartContents.Controls.Add(new LiteralControl("<tr><td>Customer Rewards Discount</td><td>(" + ((decimal)cart.OrderBy(a => a.Price).First().Price).ToString("C") + ")</td><td></td></tr>"));
                    dd.Customers.First(a => a.Customer_ID == customer.Customer_ID).TotalPoints = dd.Customers.First(a => a.Customer_ID == customer.Customer_ID).TotalPoints - 10;
                    customer = dd.Customers.First(a => a.Customer_ID == customer.Customer_ID);
                    dd.SaveChanges();
                }
                else
                {
                    dd.Customers.First(a => a.Customer_ID == customer.Customer_ID).TotalPoints = dd.Customers.First(a => a.Customer_ID == customer.Customer_ID).TotalPoints + 1;
                    dd.SaveChanges();
                    customer.TotalPoints++;
                }
                DateTime  now   = DateTime.Now.Date;
                Promotion promo = dd.Promotions.FirstOrDefault(a => a.Begin_Date <= now && a.End_Date >= now && (a.Discount_Type == "Cash Off" || a.Discount_Type == "Percent Off"));
                if (promo != null)
                {
                    if (promo.Discount_Type == "Cash Off")
                    {
                        total = total + (decimal)promo.Discount;
                    }
                    if (promo.Discount_Type == "Percent Off")
                    {
                        total = total - (total * ((decimal)promo.Discount / 100));
                    }
                }
                Order Order = new Order();
                Order.Customer_ID = customer.Customer_ID;
                if (promo != null)
                {
                    Order.Promotion = promo;
                }
                Order.Price    = cart.Sum(a => a.Price);
                Order.Ord_Date = DateTime.Now;
                Order.Points   = 0;
                dd.Orders.Add(Order);
                dd.SaveChanges();

                foreach (Product item in cart)
                {
                    Product_Order newitem = new Product_Order();
                    newitem.Order_ID   = Order.Order_ID;
                    newitem.Product_ID = item.Product_ID;
                    dd.Product_Order.Add(newitem);
                    Product prods = dd.Products.Find(item.Product_ID);
                    foreach (Product_Inventory prodInv in prods.Product_Inventory)
                    {
                        Inventory inv = dd.Inventories.Find(prodInv.Item_ID);
                        inv.Quantity -= 1;
                    }
                }
                dd.SaveChanges();
            }
            Server.Transfer("CheckoutComplete.aspx");
        }