protected void cartLabelQuantity()
        {
            if (Session["LoggedInId"] != null && Session["cartID"] != null)
            {
                int CART_QUANTITY = 0;

                int cartId = Int32.Parse(Session["cartID"].ToString());
                int userId = Int32.Parse(Session["LoggedInId"].ToString());

                using (StoreContent context = new StoreContent())
                {
                    var order = (from c in context.Orders
                                 where c.Id == cartId && c.CustomerID == userId
                                 select c).FirstOrDefault();

                    var quantity = from c in context.OrderItem
                                   where c.OrderID == order.Id
                                   select c;

                    if (order != null && quantity != null)
                    {
                        foreach (OrderItem item in quantity)
                        {
                            CART_QUANTITY += item.Quantity;

                            lblShoppingCart.Text = "Shopping Cart" + " (" + CART_QUANTITY.ToString() + ")";

                        }
                    }

                }
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            search = Request.QueryString["query"];
            using (StoreContent context = new StoreContent())
            {
                var products = (from p in context.Products
                                where p.ProductName.ToLower().Contains(search.ToLower()) || p.ProductDescription.ToLower().Contains(search.ToLower())
                                select p).ToList();
                if(products!= null)
                {
                    foreach(Products p in products) {
                        TableRow row = new TableRow();

                        TableCell cell = new TableCell();
                        cell.Text = "<img src=\"" + p.image + "\" />";
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        cell.Text = p.ProductName;
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        cell.Text = p.ProductDescription;
                        row.Cells.Add(cell);
                        tblSearch.Rows.Add(row);
                        results++;
                    }
                }
            }
            lblSearch.Text+=results+" result(s) for '"+search+"'";
        }
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            using (StoreContent context = new StoreContent())
            {
                var pwd = FinalProject.SecuredPasswordHash.GenerateHash(txtPassword.Text);
                var user = (from c in context.Customer
                            where c.UserName == txtUsername.Text && c.Password == pwd
                            select c).FirstOrDefault();

                if (user != null)
                {
                    Session["LoggedInId"] = user.Id.ToString();
                    Session["FirstName"] = user.FirstName;
                    Session["LastName"] = user.LastName;

                    lblInvalidCredentials.Visible = false;
                    updateUserName();

                    instantiateCart(Int32.Parse(Session["LoggedInId"].ToString()));

                    cartLabelQuantity();

                }
                else
                {
                    lblInvalidCredentials.Visible = true;
                    signInContent.Style.Add("visibility", "visible");

                }
            }
        }
        protected void completeOrder(int userId, int transactionId)
        {
            using (StoreContent context = new StoreContent())
            {
                var order = (from c in context.Orders
                             where c.Id == transactionId && c.CustomerID == userId
                             select c).FirstOrDefault();

                var user = (from c in context.Customer
                            where c.Id == userId
                            select c).FirstOrDefault();

                var shipAdd = (from c in context.Address
                               where c.UserName == user.UserName && c.typeAdd == "Shipping"
                               select c).FirstOrDefault();

                order.OrderStatus = "Complete";
                order.OrderDate = DateTime.Now;

                Orders newOrder = context.Orders.Create();

                newOrder.CustomerID = userId;
                newOrder.SubTotal = 0;
                newOrder.OrderDate = DateTime.Now;
                newOrder.ShippingAddress = shipAdd.Address;
                newOrder.OrderStatus = "Active";

                context.Orders.Add(newOrder);

                context.SaveChanges();

                Session["cartID"] = newOrder.Id.ToString();

            }
        }
예제 #5
0
        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            using (StoreContent context = new StoreContent())
            {
                var user = (from c in context.Customer
                            where c.UserName == txtUsername.Text && c.Password == txtPassword.Text
                            select c).FirstOrDefault();

                if (user != null)
                {
                    Session["LoggedInId"] = user.Id.ToString();
                    Session["FirstName"] = user.FirstName;
                    Session["LastName"] = user.LastName;

                    lblInvalidCredentials.Visible = false;
                    updateUserName();

                }
                else
                {
                    lblInvalidCredentials.Visible = true;
                    signInContent.Style.Add("visibility", "visible");

                }
            }
        }
예제 #6
0
        protected void populateAddresses()
        {
            if (Session["LoggedInId"] != null)
            {
                using (StoreContent context = new StoreContent())
                {
                    int userId = Int32.Parse(Session["LoggedInId"].ToString());

                    var user = (from c in context.Customer
                                where c.Id == userId
                                select c).FirstOrDefault();

                    var shipAdd = (from c in context.Address
                                   where c.UserName == user.UserName && c.typeAdd == "Shipping"
                                   select c).FirstOrDefault();

                    var billAdd = (from c in context.Address
                                   where c.UserName == user.UserName && c.typeAdd == "Billing"
                                   select c).FirstOrDefault();

                    if (user != null)
                    {
                        lblShippingAddress.Text = shipAdd.Address;
                        lblShippingCity.Text = shipAdd.City;
                        lblShippingState.Text = shipAdd.State;
                        lblShippingZip.Text = shipAdd.Zip.ToString();

                        lblBillingAddress.Text = billAdd.Address;
                        lblBillingCity.Text = billAdd.City;
                        lblBillingState.Text = billAdd.State;
                        lblBillingZip.Text = billAdd.Zip.ToString();
                    }
                }
            }
        }
예제 #7
0
        protected void populateData()
        {
            try
            {
                String productId = Request.QueryString["Id"];

                using (StoreContent content = new StoreContent())
                {
                    var currentProduct = (from c in content.Products
                                          where c.Id.ToString() == productId
                                          select c).FirstOrDefault();

                    imgProduct.ImageUrl = currentProduct.image;
                    lblProductName.Text = currentProduct.ProductName;
                    lblProductDescription.Text = currentProduct.ProductDescription;
                    lblPrice.Text = "$" + currentProduct.UnitPrice.ToString();

                    if (currentProduct.Stock > 10)
                    {
                        for (int i = 1; i <= 10; i++)
                        {
                            ListItem itemQuantity = new ListItem();
                            itemQuantity.Text = i.ToString();
                            itemQuantity.Value = i.ToString();

                            ddlQuantity.Items.Add(itemQuantity);
                        }

                    }
                    else
                    {
                        for (int i = 1; i <= currentProduct.Stock; i++)
                        {
                            ListItem itemQuantity = new ListItem();
                            itemQuantity.Text = i.ToString();
                            itemQuantity.Value = i.ToString();

                            ddlQuantity.Items.Add(itemQuantity);
                        }
                    }

                    if (currentProduct.Stock > 0)
                    {

                        btnAddToCart.Text = "Add To Cart";
                        btnAddToCart.Command += new CommandEventHandler(AddToCart);
                        btnAddToCart.CommandArgument = currentProduct.Id.ToString();
                    } else
                    {
                        btnAddToCart.Text = "Out of Stock!";
                    }

                }

            } catch
            {

            }
        }
예제 #8
0
        protected void populateOrderConfirmation()
        {
            if (Session["cartID"] != null)
            {
                int cartId = Int32.Parse(Session["cartID"].ToString());
                Decimal totalPrice = 0;

                using (StoreContent context = new StoreContent())
                {
                    var cart = (from c in context.Orders
                                where c.Id == cartId
                                select c).FirstOrDefault();

                    if (cart != null)
                    {

                        var orderItems = from c in context.OrderItem
                                          where c.OrderID == cartId
                                          select c;

                        AppTransId = cart.Id.ToString();

                        foreach (OrderItem item in orderItems)
                        {
                            var product = (from c in context.Products
                                           where c.Id == item.ProductID
                                           select c).First();

                            TableRow row = new TableRow();
                            TableCell cell;

                            cell = new TableCell();
                            cell.Text = product.ProductName;
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            cell.Text = "$" + (product.UnitPrice * item.Quantity).ToString("N2");
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            cell.Text = item.Quantity.ToString();
                            row.Cells.Add(cell);

                            tblOrderConfirmation.Rows.Add(row);

                            totalPrice += Decimal.Parse((product.UnitPrice * item.Quantity).ToString());
                        }
                    }
                }

                AppTransAmount = totalPrice.ToString();
                lblTotal.Text = "Total: $" + totalPrice.ToString("N2");

                if (totalPrice <= 0)
                {
                    Response.Redirect("index.aspx");
                }
            }
        }
예제 #9
0
        protected void populateOrders()
        {
            int userId = Int32.Parse(Session["LoggedInId"].ToString());

            using (StoreContent context = new StoreContent())
            {
                var customerOrders = from c in context.Orders
                                     where c.CustomerID == userId && c.OrderStatus == "Complete"
                                     orderby c.OrderDate descending
                                     select c;

                if (customerOrders != null)
                {
                    foreach (Orders order in customerOrders)
                    {

                        TableRow row = new TableRow();
                        TableCell cell;
                        HyperLink link;

                        cell = new TableCell();
                        link = new HyperLink();
                        link.Text = order.OrderDate.ToString("MM/dd/yyyy");
                        link.NavigateUrl = "orderdetail.aspx?Id=" + order.Id;
                        cell.Controls.Add(link);
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        cell.Text = "$" + order.SubTotal.ToString("N2");
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        cell.Text = order.OrderStatus;
                        row.Cells.Add(cell);

                        tblOrders.Rows.Add(row);

                        for (int i = 0; i < 100; i++)
                        {
                            System.Console.WriteLine("WE MADE IT HERE");
                            System.Console.Write("WE MADE IT HERE");

                        }

                    }
                } else
                {
                    TableRow row = new TableRow();
                    TableCell cell;

                    cell = new TableCell();
                    cell.Text = "You have no order history. Why not buy something now?";

                    tblOrders.Rows.Add(row);
                }
            }
        }
예제 #10
0
        protected void populateData()
        {
            using (StoreContent content = new StoreContent())
            {

                var categoryId = (from c in content.Category
                                  where c.Id == 2 //2 is the category ID for hiking
                                  select c.Id).FirstOrDefault();

                var products = from c in content.Products
                               where c.CategoryID == categoryId
                               select c;

                foreach (Products product in products)
                {

                    String productId = product.Id.ToString();

                    TableRow row = new TableRow();
                    TableCell cell;

                    cell = new TableCell();
                    Image img = new Image();
                    img.ImageUrl = product.image;
                    cell.Controls.Add(img);
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    HyperLink link = new HyperLink();
                    link.Text = product.ProductName;
                    link.NavigateUrl = "/product.aspx?Id=" + productId;
                    cell.Controls.Add(link);
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    cell.Text = "$" + product.UnitPrice.ToString();
                    row.Cells.Add(cell);

                    cell = new TableCell();
                    Button addToCartBtn = new Button();
                    addToCartBtn.Text = "Add To Cart";
                    addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                    addToCartBtn.CssClass = "addToCartButton";
                    cell.Controls.Add(addToCartBtn);
                    row.Cells.Add(cell);

                    tblProducts.Rows.Add(row);

                }

            }
        }
예제 #11
0
        protected void populateData()
        {
            try
            {
                String productId = Request.QueryString["Id"];

                using (StoreContent content = new StoreContent())
                {
                    var currentProduct = (from c in content.Products
                                          where c.Id.ToString() == productId
                                          select c).FirstOrDefault();

                    //ADD IMAGE HERE imgProductImage
                    imgProduct.ImageUrl = currentProduct.image;
                    lblProductName.Text = currentProduct.ProductName;
                    lblProductDescription.Text = currentProduct.ProductDescription;
                    lblPrice.Text = "$" + currentProduct.UnitPrice.ToString();

                    if (currentProduct.Stock > 10)
                    {
                        for (int i = 1; i <= 10; i++)
                        {
                            ListItem itemQuantity = new ListItem();
                            itemQuantity.Text = i.ToString();
                            itemQuantity.Value = i.ToString();

                            ddlQuantity.Items.Add(itemQuantity);
                        }

                    }
                    else
                    {
                        for (int i = 1; i <= currentProduct.Stock; i++)
                        {
                            ListItem itemQuantity = new ListItem();
                            itemQuantity.Text = i.ToString();
                            itemQuantity.Value = i.ToString();

                            ddlQuantity.Items.Add(itemQuantity);
                        }
                    }

                }

            } catch
            {

            }
        }
예제 #12
0
        protected void populateLinks()
        {
            using (StoreContent context = new StoreContent())
            {
                int userId = Int32.Parse(Session["LoggedInId"].ToString());

                var userFirstName = (from c in context.Customer
                                     where c.Id == userId
                                     select c.FirstName).FirstOrDefault().ToString();

                if (userFirstName != null)
                {
                    lblPageName.Text = "Welcome, " + userFirstName;
                }
            }
        }
        public void ClearData(StoreContent content)
        {
            List<string> tablenames = content.Database.SqlQuery<string>("SELECT Table_Name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME NOT LIKE '%Migration%'").ToList();
            for (int i = 0; tablenames.Count > 0; i++)
            {
                try
                {
                    content.Database.ExecuteSqlCommand(string.Format("DELETE FROM {0}", tablenames.ElementAt(i % tablenames.Count)));
                    tablenames.RemoveAt(i % tablenames.Count);
                    i = 0;
                }
                catch
                {

                }
                content.SaveChanges();
            }
        }
예제 #14
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {

                using (StoreContent content = new StoreContent())
                {

                    var checkUsername = (from c in content.Customer
                                     where c.UserName == txtUsername.Text
                                     select c).FirstOrDefault();

                    if (checkUsername == null)
                    {
                        Customer newCustomer = content.Customer.Create();
                        newCustomer.FirstName = txtFirstName.Text;
                        newCustomer.LastName = txtLastName.Text;
                        newCustomer.BillingAddress = txtBillingAddress.Text;
                        newCustomer.ShippingAddress = txtShippingAddress.Text;
                        newCustomer.City = txtCity.Text;
                        newCustomer.Zip = Int32.Parse(txtZip.Text);
                        newCustomer.State = ddlState.SelectedItem.ToString();
                        newCustomer.email = txtEmail.Text;
                        newCustomer.UserName = txtUsername.Text;
                        newCustomer.Password = txtPass1.Text;

                        if (chkNewsletter.Checked)
                        {
                            newCustomer.NewsLetter = true;
                        }
                        else
                        {
                            newCustomer.NewsLetter = false;
                        }
                    } else
                    {
                        lblPageName.Text = "Username is already taken! Please choose another.";
                        lblPageName.ForeColor = System.Drawing.Color.Red;
                    }

                }
            }
        }
예제 #15
0
        protected void updateUserName()
        {
            if (Session["LoggedInId"] != null)
            {
                using (StoreContent content = new StoreContent())
                {

                    var userId = Session["LoggedInId"].ToString();

                    var userName = (from c in content.Customer
                                    where c.Id.ToString() == userId
                                    select c.FirstName).FirstOrDefault();

                    lblSignInUsername.Text = "Hi, " + (String)userName + "! &#x25BC;";
                    userFirstName = (String)userName;
                }

                pnlSignIn.Visible = false;
                pnlSignedInOptions.Visible = true;
                lblFirstName.Text = userFirstName;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            using (StoreContent content = new StoreContent())
            {
                ClearData(content);

                Category c = new Category();
                c.Id = 00;
                c.Description = "Climbing";
                content.Category.Add(c);

                c = new Category();
                c.Id = 01;
                c.Description = "Hiking";
                content.Category.Add(c);

                c = new Category();
                c.Id = 11;
                c.Description = "Apparel";
                content.Category.Add(c);

                Products p = new Products();
                p.ProductName = "Climbing Shoes";
                p.ProductDescription = "Shoes that won't weigh you down.";
                p.UnitPrice = 119.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.image = "/images/climbing-shoes.jpg";
                p.Stock = 49;
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Harness";
                p.ProductDescription = "Hang on";
                p.UnitPrice = 79.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 28;
                p.image = "/images/climbing-harness.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Carabiner";
                p.ProductDescription = "Attach yourself to what's important";
                p.UnitPrice = 19.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 150;
                p.image = "/images/climbing-carabiner.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Belay Device";
                p.ProductDescription = "Belay with ease.";
                p.UnitPrice = 99.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 100;
                p.image = "/images/climbing-belaydevice.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Quickdraw";
                p.ProductDescription = "Precisioned attachment.";
                p.UnitPrice = 14.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 25;
                p.image = "/images/climbing-quickdraw";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Rope";
                p.ProductDescription = "Strong durable rope for scaling cliffs.";
                p.UnitPrice = 199.99;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 200;
                p.image = "/images/climbing-rope.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Climbing Cams";
                p.ProductDescription = "For when the only thing to hold on to is between a rock and another rock.";
                p.UnitPrice = 300;
                p.CategoryID = 00;
                p.Featured = false;
                p.Stock = 300;
                p.image = "/images/climbing-cams.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Hiking boots";
                p.ProductDescription = "Never lose traction";
                p.UnitPrice = 110.00;
                p.CategoryID = 01;
                p.Featured = false;
                p.Stock = 115;
                p.image = "/images/hiking-boots.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Hiking Pack";
                p.ProductDescription = "Mystery bags of all bags";
                p.UnitPrice = 200.00;
                p.CategoryID = 01;
                p.Featured = false;
                p.Stock = 35;
                p.image = "/images/hiking-pack.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Hiking Sleeping Bag";
                p.ProductDescription = "Made of that material that will hug you back when you sleep.";
                p.UnitPrice = 140.00;
                p.CategoryID = 01;
                p.Featured = false;
                p.Stock = 60;
                p.image = "/images/hiking-sleepingbag.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Apparel-Jacket";
                p.ProductDescription = "Look ready to take on the climb.";
                p.UnitPrice = 170.00;
                p.CategoryID = 11;
                p.Featured = false;
                p.Stock = 180;
                p.image = "/images/apparel-jacket.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Apparel-Pants";
                p.ProductDescription = "The swiss army knife of pants.";
                p.UnitPrice = 80.00;
                p.CategoryID = 11;
                p.Featured = false;
                p.Stock = 360;
                p.image = "/images/apparel-pants.jpg";
                content.Products.Add(p);

                p = new Products();
                p.ProductName = "Apparel-Shorts";
                p.ProductDescription = "Like the pants but half the length.";
                p.UnitPrice = 60.00;
                p.CategoryID = 11;
                p.Featured = false;
                p.Stock = 360;
                p.image = "/images/apparel-shorts.jpg";
                //this image can be changed, i just couldn't find a picture of actual shorts
                content.Products.Add(p);

                content.SaveChanges();
            }
        }
예제 #17
0
        private void AddToCart(object sender, CommandEventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                lblPageName.Text = "Please sign in or register to add items!";
                lblPageName.ForeColor = System.Drawing.Color.Red;
                return;
            }

            int addId = Convert.ToInt32(e.CommandArgument);
            int custId, cartId;
            bool hasCart = false;
            if (Session["LoggedInId"] == null)
                custId = 1;
            else
                custId = Int32.Parse(Session["LoggedInId"].ToString());

                if (Session["cartID"] == null)
            {
                using (StoreContent context = new StoreContent())
                {
                    var check = (from c in context.Orders
                                 where c.CustomerID == custId && c.OrderStatus == "Active"
                                 orderby c.Id descending
                                 select c).FirstOrDefault();
                    if(check!= null)
                    {
                        Session["cartID"] = check.Id;
                        hasCart = true;
                    }
                }
                if (!hasCart) {
                    var cart = new Orders();
                    cart.CustomerID = custId;
                    cart.OrderStatus = "Active";
                    cart.OrderDate = DateTime.Now;
                    cart.SubTotal = 0;
                    using (StoreContent context = new StoreContent())
                    {
                        context.Orders.Add(cart);
                        context.SaveChanges();
                        Session["cartID"] = cart.Id;
                    }
                }
            }
            cartId = Int32.Parse(Session["cartID"].ToString());
            using (StoreContent context = new StoreContent())
            {
                var cart = (from c in context.Orders
                            where c.Id == cartId
                            select c).FirstOrDefault();
                var item = (from p in context.Products
                            where p.Id == addId
                            select p).FirstOrDefault();
                var checkItem = (from c in context.OrderItem
                                 where c.ProductID == item.Id && c.OrderID == cart.Id
                                 select c).FirstOrDefault();
                if (checkItem != null)
                {
                    checkItem.Quantity++;
                }
                else
                {
                    var orditem = new OrderItem();
                    orditem.CustomerID = custId;
                    orditem.OrderID = cartId;
                    orditem.ProductID = item.Id;
                    orditem.Quantity = 1; //hard coded, can add function to add multiple items
                    context.OrderItem.Add(orditem);
                }
                if (cart != null)
                    cart.SubTotal += Decimal.Parse(item.UnitPrice.ToString());
                item.Stock--;   //remove from stock
                context.SaveChanges();
            }
        }
예제 #18
0
        protected void checkBoxChanged(object sender, EventArgs e)
        {
            CheckBox chkBox = (CheckBox) sender;

            if (chkBox.Checked)
            {
                lblPageName.Text = "Filtered by: " + chkBox.Text;

                using (StoreContent context = new StoreContent())
                {

                    string subcategory = chkBox.Text;
                    string filterQuery = subcategory.Substring(0, subcategory.Length - 2);

                    var categoryId = (from c in context.Category
                                      where c.Id == 1 //1 is the category ID for climbing
                                      select c.Id).FirstOrDefault();

                    var products = from c in context.Products
                                   where c.CategoryID == categoryId
                                   select c;

                    foreach (Products product in products)
                    {
                        TableRow row = tblProducts.Rows[0];
                        tblProducts.Rows.Remove(row);
                    }

                    foreach (Products product in products)
                    {
                        if (product.ProductName.Contains(filterQuery))
                        {
                            String productId = product.Id.ToString();

                            TableRow row = new TableRow();
                            TableCell cell;

                            cell = new TableCell();
                            Image img = new Image();
                            img.ImageUrl = product.image;
                            cell.Controls.Add(img);
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            HyperLink link = new HyperLink();
                            link.Text = product.ProductName;
                            link.NavigateUrl = "/product.aspx?Id=" + productId;
                            cell.Controls.Add(link);
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            cell.Text = "$" + product.UnitPrice.ToString();
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            Button addToCartBtn = new Button();
                            addToCartBtn.Text = "Add To Cart";
                            addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                            addToCartBtn.CssClass = "addToCartButton";
                            cell.Controls.Add(addToCartBtn);
                            row.Cells.Add(cell);

                            tblProducts.Rows.Add(row);

                        }

                    }
                }

            } else
            {
                lblPageName.Text = "CLIMBING";

            }

            uncheckBoxes(chkBox);
        }
예제 #19
0
        protected void priceCheckBoxChanged(object sender, EventArgs e)
        {
            CheckBox chkBox = (CheckBox)sender;

            if (chkBox.Checked)
            {
                lblPageName.Text = "Filtered by: " + chkBox.Text;
                int caseSwitch = caseSwitchMax(chkBox.Text);

                using (StoreContent context = new StoreContent())
                {
                    var categoryId = (from c in context.Category
                                      where c.Id == 1 //1 is the category ID for climbing
                                      select c.Id).FirstOrDefault();

                    var products = from c in context.Products
                                   where c.CategoryID == categoryId
                                   select c;

                    foreach (Products product in products) //Only used this as the iterator because this way it removes the exact amount of rows necessary
                    {
                        TableRow row = tblProducts.Rows[0];
                        tblProducts.Rows.Remove(row);
                    }

                    switch(caseSwitch)
                    {
                        case 1:
                            foreach(Products product in products)
                            {
                                if (product.UnitPrice <= 50)
                                {
                                    String productId = product.Id.ToString();

                                    TableRow row = new TableRow();
                                    TableCell cell;

                                    cell = new TableCell();
                                    Image img = new Image();
                                    img.ImageUrl = product.image;
                                    cell.Controls.Add(img);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    HyperLink link = new HyperLink();
                                    link.Text = product.ProductName;
                                    link.NavigateUrl = "/product.aspx?Id=" + productId;
                                    cell.Controls.Add(link);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.Text = "$" + product.UnitPrice.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    Button addToCartBtn = new Button();
                                    addToCartBtn.Text = "Add To Cart";
                                    addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                    addToCartBtn.CssClass = "addToCartButton";
                                    cell.Controls.Add(addToCartBtn);
                                    row.Cells.Add(cell);

                                    tblProducts.Rows.Add(row);
                                }

                            }
                            break;

                        case 2:
                            foreach (Products product in products)
                            {
                                if (product.UnitPrice > 50 && product.UnitPrice <= 100)
                                {
                                    String productId = product.Id.ToString();

                                    TableRow row = new TableRow();
                                    TableCell cell;

                                    cell = new TableCell();
                                    Image img = new Image();
                                    img.ImageUrl = product.image;
                                    cell.Controls.Add(img);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    HyperLink link = new HyperLink();
                                    link.Text = product.ProductName;
                                    link.NavigateUrl = "/product.aspx?Id=" + productId;
                                    cell.Controls.Add(link);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.Text = "$" + product.UnitPrice.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    Button addToCartBtn = new Button();
                                    addToCartBtn.Text = "Add To Cart";
                                    addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                    addToCartBtn.CssClass = "addToCartButton";
                                    cell.Controls.Add(addToCartBtn);
                                    row.Cells.Add(cell);

                                    tblProducts.Rows.Add(row);
                                }

                            }
                            break;

                        case 3:
                            foreach (Products product in products)
                            {
                                if (product.UnitPrice > 100 && product.UnitPrice <= 200)
                                {
                                    String productId = product.Id.ToString();

                                    TableRow row = new TableRow();
                                    TableCell cell;

                                    cell = new TableCell();
                                    Image img = new Image();
                                    img.ImageUrl = product.image;
                                    cell.Controls.Add(img);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    HyperLink link = new HyperLink();
                                    link.Text = product.ProductName;
                                    link.NavigateUrl = "/product.aspx?Id=" + productId;
                                    cell.Controls.Add(link);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.Text = "$" + product.UnitPrice.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    Button addToCartBtn = new Button();
                                    addToCartBtn.Text = "Add To Cart";
                                    addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                    addToCartBtn.CssClass = "addToCartButton";
                                    cell.Controls.Add(addToCartBtn);
                                    row.Cells.Add(cell);

                                    tblProducts.Rows.Add(row);
                                }

                            }
                            break;

                        case 4:
                            foreach (Products product in products)
                            {
                                if (product.UnitPrice > 200)
                                {
                                    String productId = product.Id.ToString();

                                    TableRow row = new TableRow();
                                    TableCell cell;

                                    cell = new TableCell();
                                    Image img = new Image();
                                    img.ImageUrl = product.image;
                                    cell.Controls.Add(img);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    HyperLink link = new HyperLink();
                                    link.Text = product.ProductName;
                                    link.NavigateUrl = "/product.aspx?Id=" + productId;
                                    cell.Controls.Add(link);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.Text = "$" + product.UnitPrice.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    Button addToCartBtn = new Button();
                                    addToCartBtn.Text = "Add To Cart";
                                    addToCartBtn.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                    addToCartBtn.CssClass = "addToCartButton";
                                    cell.Controls.Add(addToCartBtn);
                                    row.Cells.Add(cell);

                                    tblProducts.Rows.Add(row);
                                }

                            }
                            break;

                    }
                }

            } else
            {
                lblPageName.Text = "CLIMBING";
            }

            uncheckBoxes(chkBox);
        }
예제 #20
0
        protected void instantiateCart(int userId)
        {
            using (StoreContent context = new StoreContent())
            {
                var order = (from c in context.Orders
                             where c.CustomerID == userId && c.OrderStatus == "Active"
                             select c).FirstOrDefault();

                if (order != null)
                {
                    Session["cartID"] = order.Id.ToString();
                }
                else
                {

                    var user = (from c in context.Customer
                                where c.Id == userId
                                select c).First();

                    var shipAdd = (from c in context.Address
                                   where c.UserName == txtUsername.Text && c.typeAdd == "Shipping"
                                   select c).FirstOrDefault();

                    Orders newOrder = context.Orders.Create();

                    newOrder.CustomerID = userId;
                    newOrder.SubTotal = 0;
                    newOrder.OrderDate = DateTime.Now;
                    newOrder.ShippingAddress = shipAdd.Address;
                    newOrder.OrderStatus = "Active";

                    context.Orders.Add(newOrder);
                    context.SaveChanges();

                }
            }
            Response.Redirect(Request.RawUrl);
        }
예제 #21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                lblCart.Text = "Please sign in or register to view your cart!";
                lblCart.ForeColor = System.Drawing.Color.Red;

                lblCartQuantity.Text = null;

                return;
            }

            //Test cart     Session["cartID"] = 2;
            if (Session["cartID"] == null)
            {
                lblCartQuantity.Text = "(0 items)";
                lblSubtotal.Text += "0.00";
                btnCheckout.Enabled = false;
            }
            else
            {
                btnCheckout.Enabled = true;
                int cartId = Int32.Parse(Session["cartID"].ToString());
                int cartQuantity = 0;

                using (StoreContent context = new StoreContent())
                {
                    var cart = (from c in context.Orders
                                where c.Id == cartId
                                select c).First();
                    if(cart!= null)
                    {
                        int itemQty = 0;
                        bool firstFound = true;
                        var orderitems = (from o in context.OrderItem
                                         where o.OrderID == cartId
                                         select o);
                        foreach(OrderItem item in orderitems)
                        {
                            var product = (from p in context.Products
                                           where p.Id == item.ProductID
                                           select p).First();
                            int products = (from p in context.OrderItem
                                            where p.OrderID == cartId && p.ProductID == product.Id
                                            select p).Count();
                            if (products == 1)
                            {
                                cartQuantity += item.Quantity;
                                TableRow row = new TableRow();
                                TableCell cell = new TableCell();
                                cell.Text = "<img src=\"" + product.image + "\" />";
                                row.Cells.Add(cell);

                                cell = new TableCell();
                                HyperLink link = new HyperLink();
                                link.Text = product.ProductName;
                                link.NavigateUrl = "product.aspx?Id=" + product.Id;
                                cell.Controls.Add(link);
                                row.Cells.Add(cell);

                                //If item quantity is > 1, show total price and price of each unit
                                cell = new TableCell();
                                if (item.Quantity <= 1)
                                {
                                    cell.Text = "$" + product.UnitPrice.ToString("N2");
                                } else
                                {
                                    cell.Text = "$" + (product.UnitPrice * item.Quantity).ToString("N2") + " ($" + product.UnitPrice.ToString("N2") + " ea)";
                                }

                                row.Cells.Add(cell);

                                cell = new TableCell();
                                cell.Text = item.Quantity.ToString();
                                row.Cells.Add(cell);

                                cell = new TableCell();
                                Button removeFromCart = new Button();
                                removeFromCart.Text = "Remove From Cart";
                                removeFromCart.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                removeFromCart.CssClass = "actionButton";
                                removeFromCart.Command += new CommandEventHandler(RemoveFromCart);
                                removeFromCart.CommandArgument = product.Id.ToString();
                                cell.Controls.Add(removeFromCart);
                                row.Cells.Add(cell);

                                tblCart.Rows.Add(row);
                            }
                            else {
                                cartQuantity += item.Quantity;
                                itemQty+= item.Quantity;
                                TableRow row = new TableRow();
                                TableCell cell = new TableCell();
                                if (firstFound)
                                {
                                    cell.Text = "<img src=\"" + product.image + "\" />";
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    HyperLink link = new HyperLink();
                                    link.Text = product.ProductName;
                                    link.NavigateUrl = "product.aspx?Id=" + product.Id;
                                    cell.Controls.Add(link);
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.Text = product.UnitPrice.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    cell.ID = product.ProductName;
                                    cell.Text = item.Quantity.ToString();
                                    row.Cells.Add(cell);

                                    cell = new TableCell();
                                    Button removeFromCart = new Button();
                                    removeFromCart.Text = "Remove From Cart";
                                    removeFromCart.ID = product.Id.ToString(); //Will use this when adding the onClick event handler so that it can add this product ID to the user's cart
                                    removeFromCart.CssClass = "addToCartButton";
                                    removeFromCart.Command += new CommandEventHandler(RemoveFromCart);
                                    removeFromCart.CommandArgument = product.Id.ToString();
                                    cell.Controls.Add(removeFromCart);
                                    row.Cells.Add(cell);
                                    tblCart.Rows.Add(row);
                                    firstFound = false;
                                }
                                else
                                {
                                    TableCell c = tblCart.FindControl(product.ProductName.ToString()) as TableCell;
                                    c.Text = itemQty.ToString();
                                }

                            }
                        }
                        lblCartQuantity.Text = "(" + cartQuantity + " items)";
                        lblSubtotal.Text += cart.SubTotal.ToString("N2");

                    }
                }
            }
        }
        protected void populateData()
        {
            int orderId = Int32.Parse(Request.QueryString["Id"].ToString());
            int userId = Int32.Parse(Session["LoggedInId"].ToString());

            using (StoreContent context = new StoreContent())
            {

                var orderItems = from c in context.OrderItem
                                 where c.OrderID == orderId && c.CustomerID == userId
                                 select c;

                if (orderItems != null)
                {

                    foreach (OrderItem item in orderItems)
                    {

                        var product = (from c in context.Products
                                       where c.Id == item.ProductID
                                       select c).FirstOrDefault();

                        TableRow row = new TableRow();
                        TableCell cell;

                        cell = new TableCell();
                        HyperLink link = new HyperLink();
                        link.NavigateUrl = "product.aspx?Id=" + product.Id;
                        link.Text = product.ProductName;
                        cell.Controls.Add(link);
                        row.Cells.Add(cell);

                        cell = new TableCell();
                        cell.Text = item.Quantity.ToString();
                        row.Cells.Add(cell);

                        cell = new TableCell();

                        if (item.Quantity > 1)
                        {
                            cell.Text = "$" + (product.UnitPrice * item.Quantity).ToString("N2") + " ($" + product.UnitPrice.ToString("N2") + " ea)";
                        } else
                        {
                            cell.Text = "$" + product.UnitPrice.ToString("N2");
                        }

                        row.Cells.Add(cell);

                        tblOrderDetail.Rows.Add(row);

                    }

                    var orderTotal = (from c in context.Orders
                                      where c.Id == orderId
                                      select c).FirstOrDefault();

                    if (orderTotal != null)
                    {
                        lblOrder.Text = "Order Date: " + orderTotal.OrderDate.ToString("MM/dd/yyyy");
                        lblTotal.Text = orderTotal.SubTotal.ToString("N2");
                    }

                }

            }
        }
        protected void transactionApproved()
        {
            int userId = Int32.Parse(Session["LoggedInId"].ToString());
            randomDeliveryTime = rand.Next(10, 60);
            String fact = randomFact[rand.Next(0, randomFact.Length - 1)];
            String email;
            using (StoreContent context = new StoreContent())
            {
                var customerEmail = (from c in context.Customer
                                     where c.Id == userId
                                     select c).FirstOrDefault();

                email = customerEmail.email.ToString();
            }

            lblPageName.Text = "CHECKOUT SUCCESSFUL";
            lblStatus.Text = "The transaction was approved. Your credit card will be charged $" + transactionAmount.ToString();
            lblShipping.Text = "Your order will be shipped by supersonic drone for free!";
            lblDelivery.Text = "Drone will depart in 15 minutes and arrive at your doorstep in " + randomDeliveryTime + " minutes!";
            lblWarning.Text = "Please watch the sky when opening your door, as Above Treeline accepts no liability for customers hit by flying boxes.";
            lblConfirmationEmail.Text = "You should receive an order confirmation shortly at " + email;
            lblRandomFact.Text = "Did you know? " + fact;

            completeOrder(userId, transactionId);
        }
예제 #24
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {

                using (StoreContent content = new StoreContent())
                {

                    var checkUsername = (from c in content.Customer
                                     where c.UserName == txtUsername.Text
                                     select c).FirstOrDefault();

                    if (checkUsername == null)
                    {

                        Customer newCustomer = content.Customer.Create();
                        newCustomer.FirstName = txtFirstName.Text;
                        newCustomer.LastName = txtLastName.Text;

                        //adding different type of addresses

                        //billing first
                        TypeofAddress add = new TypeofAddress();
                        add.UserName = txtUsername.Text;
                        add.typeAdd = "Billing";
                        add.Address = txtBillingAddress.Text;
                        add.City = txtBillingCity.Text;
                        add.State = ddlBillingState.SelectedItem.ToString();
                        add.Zip = Int32.Parse(txtBillingZip.Text);
                        content.Address.Add(add);

                        //shipping address now
                        add = new TypeofAddress();
                        add.UserName = txtUsername.Text;
                        add.typeAdd = "Shipping";
                        add.Address = txtShippingAddress.Text;
                        add.City = txtShippingCity.Text;
                        add.State = ddlShippingState.SelectedItem.ToString();
                        add.Zip = Int32.Parse(txtShippingZip.Text);
                        content.Address.Add(add);

                        newCustomer.email = txtEmail.Text;
                        newCustomer.UserName = txtUsername.Text;

                        //password will be hashed here
                        newCustomer.Password = FinalProject.SecuredPasswordHash.GenerateHash(txtPass1.Text);

                        if (chkNewsletter.Checked)
                        {
                            newCustomer.NewsLetter = true;
                        }
                        else
                        {
                            newCustomer.NewsLetter = false;
                        }

                        content.Customer.Add(newCustomer);
                        content.SaveChanges();

                        Session["LoggedInId"] = newCustomer.Id;
                        Response.Redirect("account.aspx?Id=" + newCustomer.Id.ToString());

                    } else
                    {
                        lblPageName.Text = "Username is already taken! Please choose another.";
                        lblPageName.ForeColor = System.Drawing.Color.Red;
                    }

                }
            }
        }
        protected void verifyUser()
        {
            using (StoreContent context = new StoreContent())
            {
                try {
                    int userId = Int32.Parse(Session["LoggedInId"].ToString());
                    int orderId = Int32.Parse(Request.QueryString["Id"].ToString());

                    var order = (from c in context.Orders
                                 where c.Id == orderId && c.CustomerID == userId
                                 select c).FirstOrDefault();

                    if (order == null)
                    {
                        Response.Redirect("index.aspx");
                    }

                } catch
                {
                    Response.Redirect("index.aspx");
                }

            }
        }
예제 #26
0
        private void RemoveFromCart(object sender, CommandEventArgs e)
        {
            int remId = Convert.ToInt32(e.CommandArgument);
            int cartId = Int32.Parse(Session["cartID"].ToString());

            using (StoreContent context = new StoreContent())
            {
                var items = (from o in context.OrderItem
                            where o.OrderID == cartId && o.ProductID == remId
                            select o).ToList();
                var cart = (from c in context.Orders
                            where c.Id == cartId
                            select c).FirstOrDefault();
                var product = (from p in context.Products
                               where p.Id == remId
                               select p).First();
                foreach (OrderItem item in items)
                {
                    cart.SubTotal -= (decimal)(item.Quantity * product.UnitPrice);
                    product.Stock += item.Quantity;
                    context.OrderItem.Remove(item);
                    context.SaveChanges();
                }
            }
            Response.Redirect("cart.aspx");
        }
예제 #27
0
        private void AddToCart(object sender, CommandEventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                lblProductName.Text = "Please sign in or register to add items!";
                lblProductName.ForeColor = System.Drawing.Color.Red;
                return;
            }

            int addId = Convert.ToInt32(e.CommandArgument);
            int custId, cartId;
            bool hasCart = false;
            if (Session["LoggedInId"] == null)
                custId = 1;
            else
                custId = Int32.Parse(Session["LoggedInId"].ToString());

            if (Session["CartID"] == null)
            {
                using (StoreContent context = new StoreContent())
                {
                    var check = (from c in context.Orders
                                 where c.CustomerID == custId && c.OrderStatus == "Active"
                                 orderby c.Id descending
                                 select c).FirstOrDefault();
                    if (check != null)
                    {
                        Session["cartID"] = check.Id;
                        hasCart = true;
                    }
                }
                if (!hasCart)
                {
                    var cart = new Orders();
                    cart.CustomerID = custId;
                    cart.OrderStatus = "Active";
                    cart.OrderDate = DateTime.Now;
                    cart.SubTotal = 0;
                    using (StoreContent context = new StoreContent())
                    {
                        context.Orders.Add(cart);
                        context.SaveChanges();
                        Session["cartID"] = cart.Id;
                    }
                }
            }
            cartId = Int32.Parse(Session["cartID"].ToString());
            using (StoreContent context = new StoreContent())
            {
                int quantityToAdd;

                var cart = (from c in context.Orders
                            where c.Id == cartId
                            select c).FirstOrDefault();
                var item = (from p in context.Products
                            where p.Id == addId
                            select p).FirstOrDefault();
                var checkItem = (from c in context.OrderItem
                                 where c.ProductID == item.Id && c.OrderID == cart.Id
                                 select c).FirstOrDefault();

                if (checkItem != null)
                {
                    checkItem.Quantity = checkItem.Quantity + Int32.Parse(ddlQuantity.SelectedValue);
                    quantityToAdd = Int32.Parse(ddlQuantity.SelectedValue);
                }
                else
                {

                    var orditem = new OrderItem();
                    orditem.CustomerID = custId;
                    orditem.OrderID = cartId;
                    orditem.ProductID = item.Id;

                    if (Int32.Parse(ddlQuantity.SelectedValue) > 1)
                    {
                        quantityToAdd = Int32.Parse(ddlQuantity.SelectedValue);
                        orditem.Quantity = quantityToAdd;
                    }
                    else
                    {
                        quantityToAdd = 1;
                        orditem.Quantity = Int32.Parse(ddlQuantity.SelectedValue);
                    }

                    context.OrderItem.Add(orditem);
                }

                if (cart != null)
                {
                    cart.SubTotal += Decimal.Parse((item.UnitPrice * Int32.Parse(ddlQuantity.SelectedValue)).ToString()); //Subtotal now reflects unit price * quantity of units  --RID
                }
                item.Stock = item.Stock - quantityToAdd;   //remove from stock
                context.SaveChanges();

            }

            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }