Beispiel #1
0
 public void setVisibility()
 {
     if (Session["ID"] == null)
     {
         pnlCheckout.Visible = false;
     }
     else
     {
         int id = Convert.ToInt32(Session["ID"]);
         using (AABZContext context = new AABZContext())
         {
             User ui = (from info in context.Users
                        where info.Id == id
                        select info).FirstOrDefault();
             foreach (UserInfo info in ui.UserInfoes)
             {
                 if (info.isBilling)
                 {
                     pnlBillingAddress.Visible = false;
                     return;
                 }
             }
         }
     }
 }
Beispiel #2
0
        public void btn_login(Object sender, EventArgs e)
        {
            var email = txtUserName.Text;
            var Pass  = SecurePass.GenerateHash(txtPwd.Text);

            using (AABZContext context = new AABZContext())
            {
                try
                {
                    var s = (from c in context.Users
                             where c.email == email && c.password == Pass
                             select c).FirstOrDefault();
                    //if valid create session and session cookie
                    if (s != null)
                    {
                        Session["ID"]      = s.Id.ToString();
                        panelLogin.Visible = false;
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        lblResults.Text = "User Name or Password are incorrect.";
                    }
                }
                catch (Exception ex)
                {
                    lblResults.Text = ex.ToString();
                }
            }
        }
Beispiel #3
0
        public double getPrice()
        {
            if (Session["ID"] != null)
            {
                int id = Convert.ToInt32(Session["ID"]);

                using (AABZContext context = new AABZContext())
                {
                    Order order = (from o in context.Orders
                                   where o.user_id == id
                                   orderby o.Id descending
                                   select o).FirstOrDefault();

                    double result = 0;

                    foreach (ProductsOrder po in order.ProductsOrders)
                    {
                        result += po.price;
                    }

                    return(result);
                }
            }
            else
            {
                return(0);
            }
        }
Beispiel #4
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["ID"] != null)
     {
         using (AABZContext context = new AABZContext())
         {
             var user = context.Users.Find(Convert.ToInt32(Session["ID"]));
             if (user != null)
             {
                 linkLogIn.Visible      = false;
                 linkLogout.Visible     = true;
                 linkSignUp.Text        = "<span class='glyphicon glyphicon-user'></span> " + user.first_name + " " + user.last_name;
                 linkSignUp.NavigateUrl = "~/OrderHistory.aspx";
             }
             else
             {
                 linkLogIn.Visible      = true;
                 linkLogout.Visible     = false;
                 linkLogIn.NavigateUrl  = "~/Login.aspx";
                 linkSignUp.Text        = "<span class='glyphicon glyphicon-user'></span> Sign Up";
                 linkSignUp.NavigateUrl = "~/Register.aspx";
             }
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     using (AABZContext context = new AABZContext())
     {
         int id = GetId();
         ProductsListDataSource.Where = "it.id == " + id.ToString();
         ProductsListDataSource.DataBind();
     }
 }
Beispiel #6
0
        protected void ResetModel()
        {
            // Use this method to recreate the database.
            // For some reason it doesn't drop the data base, so before doing this:
            //  - Remove the database file from App_Data
            //  - Remove the Connection from Server Explorer

            Database.SetInitializer(new AABZContextInitializer());
            using (AABZContext entities = new AABZContext())
            {
                var c = entities.Categories.Find("Accessories");
                Response.Write(c.Name);
            }
        }
Beispiel #7
0
 public void refreshCart()
 {
     if (Session["ID"] != null)
     {
         int id = Convert.ToInt32(Session["ID"]);
         using (AABZContext context = new AABZContext())
         {
             Model.Cart cart = (from c in context.Carts
                                where c.user_id == id
                                select c).FirstOrDefault();
             rptCart.DataSource = cart.products_cart.ToList();
             rptCart.DataBind();
         }
     }
 }
Beispiel #8
0
 protected void btnDelete_Command(object sender, CommandEventArgs e)
 {
     if (Session["ID"] != null)
     {
         int id = Convert.ToInt32(e.CommandArgument);
         using (AABZContext context = new AABZContext())
         {
             ProductsCart pc = (from p in context.ProductsCarts
                                where p.Id == id
                                select p).FirstOrDefault();
             context.ProductsCarts.Remove(pc);
             context.SaveChanges();
             refreshCart();
         }
     }
 }
Beispiel #9
0
        public void RedirectUser()
        {
            if (Session["ID"] != null)
            {
                int    id = Convert.ToInt32(Session["ID"]);
                int    orderId;
                double price;

                using (AABZContext context = new AABZContext())
                {
                    //This ensures that order is the most recent order the user has made.
                    Order order = (from o in context.Orders
                                   where o.user_id == id
                                   orderby o.Id descending
                                   select o).FirstOrDefault();
                    orderId = order.Id;
                    int        userId = Convert.ToInt32(Session["ID"].ToString());
                    Model.Cart cart   = (from c in context.Carts
                                         where c.user_id == userId
                                         select c).FirstOrDefault();
                    context.ProductsCarts.RemoveRange(context.ProductsCarts.Where(x => x.cart_id == cart.user_id));
                    context.SaveChanges();
                    price = getTotalOrderCost(order);
                }

                //Assign the values for the properties we need to pass to the service
                String AppId          = System.Configuration.ConfigurationManager.AppSettings["CreditAppId"];
                String SharedKey      = System.Configuration.ConfigurationManager.AppSettings["CreditAppSharedKey"];
                String AppTransId     = orderId.ToString();
                String AppTransAmount = price.ToString();

                // Hash the values so the server can verify the values are original
                String hash = HttpUtility.UrlEncode(CreditAuthorizationClient.GenerateClientRequestHash(SharedKey, AppId, AppTransId, AppTransAmount));

                //Create the URL and  concatenate  the Query String values
                String url = "http://ectweb2.cs.depaul.edu/ECTCreditGateway/Authorize.aspx";
                url = url + "?AppId=" + AppId;
                url = url + "&TransId=" + AppTransId;
                url = url + "&AppTransAmount=" + AppTransAmount;
                url = url + "&AppHash=" + hash;

                //Redirect the User to the Service
                //Response.Redirect(url);
                Response.Redirect("~/OrderHistory.aspx");
            }
        }
Beispiel #10
0
 public ICollection <UserInfo> getUserInfo()
 {
     if (Session["ID"] != null)
     {
         int id = Convert.ToInt32(Session["ID"]);
         using (AABZContext context = new AABZContext())
         {
             User result = (from ui in context.Users
                            where ui.Id == id
                            select ui).FirstOrDefault();
             return(result.UserInfoes);
         }
     }
     else
     {
         return(null);
     }
 }
Beispiel #11
0
 protected void removeItem(object sender, CommandEventArgs e)
 {
     if (Session["ID"] != null)
     {
         int id = Convert.ToInt32(e.CommandArgument);
         using (AABZContext context = new AABZContext())
         {
             int        userId = Convert.ToInt32(Session["ID"]);
             Model.Cart cart   = (from c in context.Carts
                                  where c.user_id == userId
                                  select c).FirstOrDefault();
             ProductsCart pc = (from p in context.ProductsCarts
                                where p.Id == id
                                select p).FirstOrDefault();
             cart.products_cart.Remove(pc);
             context.ProductsCarts.Remove(pc);
             context.SaveChanges();
         }
     }
 }
Beispiel #12
0
        public double getTotalPrice()
        {
            if (Session["ID"] != null)
            {
                int id = Convert.ToInt32(Session["ID"]);
                using (AABZContext context = new AABZContext())
                {
                    Model.Cart cart = (from c in context.Carts
                                       where c.user_id == id
                                       select c).FirstOrDefault();

                    double cost = 0;
                    foreach (ProductsCart pc in cart.products_cart)
                    {
                        cost += (pc.quantity * pc.Product.price);
                    }
                    return(cost);
                }
            }
            return(0);
        }
Beispiel #13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ID"] == null)
            {
                Response.Redirect("Default.aspx");
            }
            if (!IsPostBack)
            {
                var id = Int32.Parse(Session["ID"].ToString());
                using (AABZContext context = new AABZContext())
                {
                    try
                    {
                        var history = (from o in context.Orders
                                       where o.user_id == id
                                       select o).ToList();
                        foreach (var entry in history)
                        {
                            TableRow  row = new TableRow();
                            TableCell cell;
                            cell      = new TableCell();
                            cell.Text = entry.Id.ToString();
                            row.Cells.Add(cell);

                            cell      = new TableCell();
                            cell.Text = entry.ShippingAddress.address_1 + "<br/>" + entry.ShippingAddress.address_2;
                            row.Cells.Add(cell);

                            cell      = new TableCell();
                            cell.Text = entry.BillingAddress.address_1 + "<br/>" + entry.BillingAddress.address_2;
                            row.Cells.Add(cell);

                            cell = new TableCell();
                            String products = "";
                            double total    = 0;
                            foreach (ProductsOrder p in entry.ProductsOrders)
                            {
                                total    += p.price * p.quantity;
                                products += "#" + p.Id + " " + p.Product.name + "<br/>";
                            }
                            cell.Text = products;
                            row.Cells.Add(cell);
                            cell     = new TableCell();
                            products = "";
                            foreach (ProductsOrder p in entry.ProductsOrders)
                            {
                                total    += p.price * p.quantity;
                                products += p.quantity + " X " + p.price + " = " + (p.quantity * p.price) + "<br/>";
                            }
                            products += "Total:  $" + total;
                            cell.Text = products;
                            row.Cells.Add(cell);

                            tblData.Rows.Add(row);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Beispiel #14
0
        protected void btnAddCart_Click(object sender, CommandEventArgs e)
        {
            //Do Something to add product to cart.
            //To get the product it use e.CommandArgument

            if (Session["ID"] != null)
            {
                int userID    = Convert.ToInt32(Session["ID"]);
                int productID = Convert.ToInt32(e.CommandArgument);

                using (AABZContext entities = new AABZContext())
                {
                    var cart = entities.Carts.Find(userID);

                    if (cart == null)
                    {
                        cart = entities.Carts.Create();

                        cart.user_id    = userID;
                        cart.creation   = DateTime.Now;
                        cart.expiration = DateTime.Now.AddDays(7);

                        entities.Carts.Add(cart);
                        entities.SaveChanges();
                    }
                    else
                    {
                        cart.creation   = DateTime.Now;
                        cart.expiration = DateTime.Now.AddDays(7);

                        entities.SaveChanges();
                    }

                    ProductsCart cartItem;

                    try
                    {
                        cartItem = (from productInCart in entities.ProductsCarts
                                    where productInCart.cart_id == userID && productInCart.product_id == productID
                                    select productInCart).First();
                    }
                    catch (Exception)
                    {
                        cartItem = null;
                    }


                    if (cartItem == null)
                    {
                        cartItem            = entities.ProductsCarts.Create();
                        cartItem.cart_id    = cart.user_id;
                        cartItem.product_id = productID;
                        cartItem.quantity   = 1;

                        entities.ProductsCarts.Add(cartItem);
                        entities.SaveChanges();
                    }
                    else
                    {
                        cartItem.quantity += 1;
                        entities.SaveChanges();
                    }
                }
            }
            else
            {
                Response.Redirect("~/Login.aspx");
            }
        }
Beispiel #15
0
        protected void BtnSubmit(Object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                using (AABZContext entities = new AABZContext())
                {
                    //try to add user to database, return error if fails
                    try
                    {
                        var isValid = (from c in entities.Users
                                       where c.email == txtEmail.Text
                                       select c).FirstOrDefault();
                        if (isValid != null && isValid.Equals(txtEmail.Text))
                        {
                            error.Text = "Username is not valid!";
                            return;
                        }
                        var user = entities.Users.Create();
                        user.first_name = txtFname.Text;
                        user.last_name  = txtLastName.Text;
                        user.email      = txtEmail.Text;
                        var Pass = SecurePass.GenerateHash(txtPass.Text);
                        user.password = Pass;

                        var info = entities.UserInfoes.Create();
                        info.user_id   = user.Id;//LINK TO USER
                        info.address_1 = txtAdd.Text;
                        info.address_2 = txtAdd2.Text;
                        info.city      = txtCity.Text;
                        info.state     = txtState.Text;
                        info.zipcode   = txtZip.Text;
                        info.phone     = txtPhone.Text;

                        if (!chkBill.Checked)
                        {
                            info.isBilling = false;
                            var billingInfo = entities.UserInfoes.Create();
                            billingInfo.address_1 = txtBill1.Text;
                            billingInfo.address_2 = txtBill2.Text;
                            billingInfo.user_id   = user.Id;//LINK TO USER
                            billingInfo.city      = billcity.Text;
                            billingInfo.state     = billstate.Text;
                            billingInfo.zipcode   = billzip.Text;
                            billingInfo.isBilling = true;
                            user.UserInfoes.Add(billingInfo);
                        }
                        else
                        {
                            info.isBilling = true;
                        }
                        user.UserInfoes.Add(info);
                        entities.Users.Add(user);
                        entities.UserInfoes.Add(info);
                        entities.SaveChanges();
                        Response.Redirect("Login.aspx");
                        //load information to panel
                        //show panel and hide form
                    }
                    catch (Exception ex)
                    {
                        error.Text = "Error Occured. Error Info: " + ex.Message;
                    }
                }
            }
        }
Beispiel #16
0
        protected Order createOrder()
        {
            if (Session["ID"] != null)
            {
                try
                {
                    int userId = Convert.ToInt32(Session["ID"].ToString());
                    using (AABZContext context = new AABZContext())
                    {
                        Order order = new Order();//build order
                        //get user cart
                        Model.Cart cart = (from c in context.Carts
                                           where c.user_id == userId
                                           select c).FirstOrDefault();
                        //get user
                        User usr = (from u in context.Users
                                    where u.Id == userId
                                    select u).First();
                        order.User = usr;//set order user

                        List <UserInfo> ui = (from info in context.UserInfoes
                                              where info.user_id == userId
                                              select info).ToList();
                        if (ui.Count == 1 && ui.ElementAt(0).isBilling)//if one address and is billing
                        {
                            UserInfo usrinfo = ui.ElementAt(0);
                            order.BillingAddress   = usrinfo;
                            order.billing_address  = usrinfo.Id;
                            order.ShippingAddress  = usrinfo;
                            order.shipping_address = usrinfo.Id;
                        }
                        else
                        {
                            foreach (UserInfo info in ui)//for each address assign apropriately
                            {
                                if (info.isBilling)
                                {
                                    order.BillingAddress  = info;
                                    order.billing_address = info.Id;
                                }
                                else
                                {
                                    order.ShippingAddress  = info;
                                    order.shipping_address = info.Id;
                                }
                            }
                        }
                        context.Orders.Add(order);
                        context.SaveChanges();

                        ProductsOrder po = new ProductsOrder();
                        //for each product in cart create product order and add to order
                        List <ProductsOrder> orders = new List <ProductsOrder>();
                        foreach (ProductsCart pc in cart.products_cart)
                        {
                            po            = new ProductsOrder();
                            po.order_id   = order.Id;
                            po.Product    = pc.Product;
                            po.product_id = pc.product_id;
                            po.quantity   = pc.quantity;
                            po.price      = pc.Product.price * pc.quantity;
                            po.Order      = order;
                            context.PoductsOrders.Add(po);
                            orders.Add(po);
                        }
                        order.ProductsOrders = orders;
                        //create payment
                        Payment payment = new Payment();
                        payment.cc_name   = txtCcName.Text;
                        payment.cc_number = txtCcNumber.Text;
                        payment.cc_month  = Convert.ToInt32(drpCcMonth.SelectedValue);
                        payment.cc_year   = Convert.ToInt32(drpCcYear.SelectedValue);
                        payment.cc_ccv    = Convert.ToInt32(txtCcCvv.Text);
                        order.Payments    = payment;//set payment
                        payment.Order     = order;

                        /*
                         * if (ui.isBilling)
                         * {
                         *  order.BillingAddress = ui;
                         * }
                         * else
                         * {
                         *  UserInfo ui2 = new UserInfo();
                         *  ui2.User = ui.User;
                         *  ui2.address_1 = txtAddress1.Text;
                         *  ui2.address_2 = txtAddress2.Text;
                         *  ui2.city = txtCity.Text;
                         *  ui2.state = txtState.Text;
                         *  ui2.zipcode = txtZipCode.Text;
                         *  ui2.phone = ui.phone;
                         *  order.BillingAddress = ui2;
                         * }
                         */

                        payment.order_id = order.Id;
                        context.Payments.Add(payment);
                        context.SaveChanges();
                        return(order);
                    }
                }catch (DbEntityValidationException e)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }