protected void registerBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (ECTDBContext entities = new ECTDBContext())
                {
                    var member  = entities.Customers.Create();
                    var address = entities.Addresses.Create();
                    member.FirstName      = firstNameTxt.Text;
                    member.LastName       = lastNameTxt.Text;
                    member.Email          = emailTxt.Text;
                    member.UserName       = userNameTxt2.Text;
                    member.Password       = SecuredPassword.GenerateHash(passwordTxt2.Text);
                    member.DateRegistered = DateTime.Now.Date;
                    entities.Customers.Add(member);
                    entities.SaveChanges();

                    var pwdHash = SecuredPassword.GenerateHash(passwordTxt2.Text);
                    var user    = (from u in entities.Customers
                                   where u.UserName == userNameTxt2.Text && u.Password == pwdHash
                                   select u).FirstOrDefault();
                    address.CustomerID  = user.ID;
                    address.Address1    = addressTxt.Text;
                    address.City        = cityTxt.Text;
                    address.State       = stateTxt.Text;
                    address.AddressType = "Billing";
                    entities.Addresses.Add(address);
                    entities.Addresses.Add(address);
                    entities.SaveChanges();
                    clearTextBoxes(registerControl);
                    registerSuccessLbl.Visible = true;
                }
            }
        }
Beispiel #2
0
 protected void update_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         pnlMain.Visible   = true;
         pnlUpdate.Visible = false;
         using (ECTDBContext entities = new ECTDBContext())
         {
             var userID   = Int32.Parse(Session["LoggedInId"].ToString());
             var userInfo = (from u in entities.Customers
                             where u.ID == userID
                             select u).FirstOrDefault();
             var userAddress = (from a in entities.Addresses
                                where a.CustomerID == userID
                                select a).FirstOrDefault();
             userInfo.Email       = emailTxt.Text;
             userInfo.FirstName   = firstNameTxt.Text;
             userInfo.LastName    = lastNameTxt.Text;
             userInfo.UserName    = userNameTxt2.Text;
             userAddress.Address1 = addressTxt.Text;
             userAddress.State    = stateTxt.Text;
             userAddress.City     = cityTxt.Text;
             entities.SaveChanges();
         }
         Response.Redirect("Account.aspx");
     }
 }
Beispiel #3
0
        private List <String> getProducts(Object ID)
        {
            int orderID = Convert.ToInt32(ID);

            using (ECTDBContext entities = new ECTDBContext())
            {
                var products = (from od in entities.OrderDetails
                                where od.OrderID == orderID
                                select od.ProductName).ToList();
                return(products);
            }
        }
Beispiel #4
0
        private List <int> getQuantities(Object ID)
        {
            int orderID = Convert.ToInt32(ID);

            using (ECTDBContext entities = new ECTDBContext())
            {
                var quantities = (from od in entities.OrderDetails
                                  where od.OrderID == orderID
                                  select od.Quantity).ToList();

                return(quantities);
            }
        }
Beispiel #5
0
        public void placeOrderClick(object sender, EventArgs e)
        {
            if (Session["update"].ToString() == ViewState["update"].ToString())
            {
                using (ECTDBContext context = new ECTDBContext())
                {
                    var order = (from or in context.Orders
                                 where or.CustomerID == userID && or.IsCart == "true"
                                 select or).FirstOrDefault();
                    if (order != null)
                    {
                        String cost            = order.Total.ToString();
                        String orderID         = order.ID.ToString();
                        var    orderDetailList = (from od in context.OrderDetails
                                                  where od.OrderID == order.ID
                                                  select od).ToList();
                        foreach (OrderDetail od in orderDetailList)
                        {
                            if (od.OrderID == order.ID)
                            {
                                int quantity  = od.Quantity;
                                int productID = od.ProductID;
                                var product   = (from p in context.Products
                                                 where p.ID == productID
                                                 select p).FirstOrDefault();

                                product.TotalOnHand -= quantity;
                                order.IsCart         = "false";
                                order.Date           = DateTime.Now.ToString("MM/dd/yy");
                                Session["cartCount"] = "0";
                                context.SaveChanges();



                                RedirectUser(orderID, cost);
                            }
                        }

                        Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
                    }
                }
            }
            else
            {
                return;
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
                }
                userID = int.Parse(Session["LoggedInId"].ToString());

                //update cart text in header
                String cartCount = Session["cartCount"].ToString();
                this.Master.CartText = cartCount;
                String userName = Session["UserName"].ToString();
                Master.UserNameHeader = userName;
                Master.FindControl("signOut").Visible = true;

                using (ECTDBContext entities = new ECTDBContext())
                {
                    var sorted = entities.Products.OrderBy(c => c.ID);

                    var firstRowProducts = (from p in sorted
                                            select p).Skip(0).Take(5).ToList();

                    var secondRowProducts = (from p in sorted
                                             select p).Skip(5).Take(5).ToList();



                    if (!Page.IsPostBack)
                    {
                        productListView.DataSource  = firstRowProducts;
                        productListView2.DataSource = secondRowProducts;

                        productListView.DataBind();
                        productListView2.DataBind();
                    }
                }
            }
        }
Beispiel #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else if (!IsPostBack)
            {
                Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            }


            userID = int.Parse(Session["LoggedInId"].ToString());
            String cartCount = Session["cartCount"].ToString();

            Master.CartText = cartCount;
            String userName = Session["UserName"].ToString();

            Master.UserNameHeader = userName;
            Master.FindControl("signOut").Visible = true;

            using (ECTDBContext context = new ECTDBContext())
            {
                var orderList = (from o in context.Orders
                                 where o.CustomerID == userID && o.IsCart == "true"
                                 select o).ToList();
                if (orderList.Count != 0)
                {
                    var order           = orderList.First();
                    var orderDetailList = (from od in context.OrderDetails
                                           where od.OrderID == order.ID
                                           select od).ToList();
                    if (!Page.IsPostBack)
                    {
                        totalListView.DataSource = orderList;

                        summaryListView.DataSource = orderDetailList;
                        totalListView.DataBind();

                        summaryListView.DataBind();
                    }
                }
            }
        }
        protected void login(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (ECTDBContext context = new ECTDBContext())
                {
                    var pwdHash = SecuredPassword.GenerateHash(txtPassword.Text);
                    var user    = (from u in context.Customers
                                   where u.UserName == txtUserName.Text && u.Password == pwdHash
                                   select u).FirstOrDefault();
                    if (user == null)
                    {
                        errorMessage.Visible = true;
                    }
                    else
                    {
                        Session["LoggedInId"] = user.ID.ToString();
                        Session["FirstName"]  = user.FirstName;
                        Session["LastName"]   = user.LastName;
                        Session["UserName"]   = user.UserName;

                        var userOrder = (from order in context.Orders
                                         where order.CustomerID == user.ID && order.IsCart == "true"
                                         select order).FirstOrDefault();
                        //if user has existing cart, restore cart number at top of page and store session variable
                        if (userOrder != null)
                        {
                            var cart = (from od in context.OrderDetails
                                        where od.OrderID == userOrder.ID
                                        select od.Quantity).ToList();
                            int cartCount = cart.Sum();
                            Session["cartCount"] = cartCount.ToString();
                        }
                        else
                        {
                            Session["cartCount"] = "0";
                        }

                        Response.Redirect("Home.aspx");
                    }
                }
            }
        }
Beispiel #9
0
        public void removeFromCart(Object sender, EventArgs e)
        {
            if (Session["update"].ToString() == ViewState["update"].ToString())
            {
                Button b = (Button)sender;
                //store the commandargument attached to the delete button
                int id = Convert.ToInt32(b.CommandArgument.ToString());
                using (ECTDBContext context = new ECTDBContext())
                {
                    var orderDetail = (from o in context.OrderDetails
                                       where o.ID == id
                                       select o).FirstOrDefault();
                    Decimal deletePrice = orderDetail.Cost * orderDetail.Quantity;
                    context.OrderDetails.Remove(orderDetail);
                    context.SaveChanges();
                    //update cart item number at top of page
                    int cartCount = int.Parse(Session["cartCount"].ToString());
                    cartCount           -= orderDetail.Quantity;
                    Session["cartCount"] = cartCount;
                    Master.CartText      = cartCount.ToString();
                    var updatedOrder = (from order in context.Orders
                                        where order.CustomerID == userID && order.IsCart == "true"
                                        select order).ToList();
                    var newOrder = updatedOrder.First();
                    newOrder.Total -= deletePrice;
                    context.SaveChanges();

                    var updatedOrderDetail = (from od in context.OrderDetails
                                              where od.OrderID == newOrder.ID
                                              select od).ToList();

                    summaryListView.DataSource = updatedOrderDetail;
                    totalListView.DataSource   = updatedOrder;
                    summaryListView.DataBind();
                    totalListView.DataBind();
                }
                Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            }
            else
            {
                return;
            }
        }
Beispiel #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedInId"] == null)
            {
                Response.Redirect("Login.aspx");
            }
            else
            {
                int    userID    = Int32.Parse(Session["LoggedInId"].ToString());
                String cartCount = Session["cartCount"].ToString();
                Master.CartText = cartCount;
                String userName = Session["UserName"].ToString();
                Master.UserNameHeader = userName;
                Master.FindControl("signOut").Visible = true;

                //To display order history gridview
                SqlDataSource1.SelectParameters.Add("userID", userID.ToString());
                SqlDataSource1.SelectParameters.Add("false", "false");
                SqlDataSource1.SelectCommand = "select Orders.ID, Orders.Total, Orders.Date from Orders where @userID = Orders.CustomerID and Orders.IsCart = @false";


                using (ECTDBContext context = new ECTDBContext())
                {
                    var customer = (
                        from c in context.Customers
                        where c.ID == userID
                        select c).FirstOrDefault();
                    var address = (
                        from a in context.Addresses
                        where a.CustomerID == userID
                        select a).FirstOrDefault();


                    lblFirst.Text   = "First Name: " + customer.FirstName;
                    lblLast.Text    = "Last Name: " + customer.LastName;
                    lblEmail.Text   = "Email: " + customer.Email;
                    lblAddress.Text = "Address: " + address.Address1;
                    lblCity.Text    = "City: " + address.City;
                    lblState.Text   = "State: " + address.State;
                }
            }
        }
Beispiel #11
0
        public void createNewCart(int itemID, int quantity)
        {
            using (ECTDBContext context = new ECTDBContext())
            {
                //Edit the cart number at top of page
                int cartCount = int.Parse(Session["cartCount"].ToString());
                cartCount           += quantity;
                Session["cartCount"] = cartCount;
                Master.CartText      = cartCount.ToString();


                //Build new Order entry
                var newOrder = new Order();
                newOrder.CustomerID        = userID;
                newOrder.IsCart            = "true";
                newOrder.Total             = 0;
                newOrder.ShippingID        = 1;
                newOrder.ShippingAddressID = 1;
                context.Orders.Add(newOrder);
                context.SaveChanges();
                //Build new OrderDetail entry
                var newOrderDetail = new OrderDetail();

                //find new order
                var newOrderVar = (from order in context.Orders
                                   where order.IsCart == "true" && order.CustomerID == userID
                                   select order).FirstOrDefault();

                newOrderDetail.OrderID = newOrderVar.ID;
                var product = (from p in context.Products
                               where p.ID == itemID
                               select p).FirstOrDefault();
                newOrderDetail.Cost        = product.Cost;
                newOrderDetail.Quantity    = quantity;
                newOrderDetail.ProductID   = itemID;
                newOrderDetail.ProductName = product.Name;
                newOrderVar.Total         += newOrderDetail.Cost * newOrderDetail.Quantity;
                context.OrderDetails.Add(newOrderDetail);
                context.SaveChanges();
            }
        }
Beispiel #12
0
 protected void passWordConfirm_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         pnlMain.Visible      = true;
         orderHistory.Visible = true;
         pnlPassword.Visible  = false;
         using (ECTDBContext entities = new ECTDBContext())
         {
             var pwdHash  = SecuredPassword.GenerateHash(passwordTxt.Text);
             var userID   = Int32.Parse(Session["LoggedInId"].ToString());
             var customer = (from c in entities.Customers
                             where c.ID == userID
                             select c).FirstOrDefault();
             if (customer.Password == pwdHash && newPasswordTxt.Text.ToString().Length > 0)
             {
                 customer.Password = SecuredPassword.GenerateHash(newPasswordTxt.Text);
                 entities.SaveChanges();
             }
         }
     }
 }
Beispiel #13
0
        public void addToCartClick(object sender, EventArgs e)
        {
            if (Session["update"].ToString() == ViewState["update"].ToString())
            {
                using (ECTDBContext context = new ECTDBContext())
                {
                    Button b = (Button)sender;
                    //store the commandargument attached to the delete button
                    int id = Convert.ToInt32(b.CommandArgument.ToString());

                    //Get quantity value from textbox
                    ListViewDataItem item         = b.NamingContainer as ListViewDataItem;
                    TextBox          quantityText = item.FindControl("quantityText") as TextBox;
                    int quantity = Convert.ToInt32(quantityText.Text);
                    if (quantity == 0)
                    {
                        return;
                    }
                    else
                    {
                        var product = (from p in context.Products
                                       where p.ID == id
                                       select p).FirstOrDefault();
                        var userOrdersList = (from o in context.Orders
                                              where o.CustomerID == userID && o.IsCart == "true"
                                              select o).ToList();
                        //If user has an existing cart
                        if (userOrdersList.Count > 0)
                        {
                            //Edit the cart number at top of page
                            int cartCount = int.Parse(Session["cartCount"].ToString());
                            cartCount           += quantity;
                            Session["cartCount"] = cartCount;
                            this.Master.CartText = cartCount.ToString();
                            var userOrders        = userOrdersList.First();
                            var repeatOrderDetail = (from or in context.OrderDetails
                                                     where or.OrderID == userOrders.ID && or.ProductID == id
                                                     select or).FirstOrDefault();
                            if (repeatOrderDetail != null)
                            {
                                repeatOrderDetail.Quantity += quantity;
                                userOrders.Total           += quantity * product.Cost;
                                context.SaveChanges();
                                var orderDetailSummary = (from orderDetail in context.OrderDetails
                                                          where orderDetail.OrderID == userOrders.ID
                                                          select orderDetail).ToList();
                                var updatedUserOrderList = (from o in context.Orders
                                                            where o.CustomerID == userID && o.IsCart == "true"
                                                            select o).ToList();
                            }
                            else
                            {
                                //Build new OrderDetail entry
                                var newOrderDetail = new OrderDetail();
                                newOrderDetail.ProductID = id;
                                //set orderID to the current order
                                newOrderDetail.OrderID     = userOrders.ID;
                                newOrderDetail.Cost        = product.Cost;
                                newOrderDetail.ProductName = product.Name;
                                newOrderDetail.Quantity    = quantity;

                                //update the running total for entire order
                                userOrders.Total += newOrderDetail.Cost * newOrderDetail.Quantity;
                                context.OrderDetails.Add(newOrderDetail);
                                context.SaveChanges();
                            }
                        }
                        //if user does not have an existing cart
                        else
                        {
                            createNewCart(id, quantity);
                        }
                    }
                }
                Session["update"] = Server.UrlEncode(System.DateTime.Now.ToString());
            }
            else
            {
                return;
            }
        }