public void SortProducts(string s)
        {
            using (var db = new ProductDb())
            {
                var p = from a in db.Products select a;
                switch (s)
                {
                case "0":
                    p = p.OrderBy(a => a.ProductName);
                    break;

                case "1":
                    p = p.OrderBy(a => a.Price);
                    break;

                case "2":
                    p = p.OrderByDescending(a => a.Price);
                    break;

                case "3":
                    p = p.OrderByDescending(a => a.Stock);
                    break;

                default:
                    p = p.OrderBy(a => a.ProductName);
                    break;
                }
                foreach (Product pr in p)
                {
                    products.Add(pr);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            List<Product> products = new List<Product>();
            using (ProductDb db = new ProductDb())
            {
                //Choose three random products
                products = db.Products.OrderBy(p => Guid.NewGuid()).Take(3).ToList();
            }
            foreach (Product p in products)
            {
                //Dynamically create links in the same style as other links on the homepage for the 3 randomly choosen products from above.
                HtmlGenericControl ColDiv = new HtmlGenericControl("div");
                ColDiv.Attributes["class"] = "col-md-4";
                HtmlGenericControl article = new HtmlGenericControl("article");
                article.Attributes["class"] = "Links";
                article.Attributes["style"] = "background-image:url(" + p.MainProductImage.ToString() + ");";
                HtmlGenericControl HoverDiv = new HtmlGenericControl("div");
                HoverDiv.Attributes["class"] = "hover";
                HtmlGenericControl h4 = new HtmlGenericControl("h4");
                h4.InnerText = p.ProductName;
                HtmlGenericControl p1 = new HtmlGenericControl("p");
                p1.InnerText = p.Description;
                HtmlGenericControl p2 = new HtmlGenericControl("p");
                p2.InnerHtml = "<a href='ProductDetails.aspx?ProductId="+p.ProductId+"' class='btn btn-info btn-sm'>Go</a>";
                HoverDiv.Controls.Add(h4);
                HoverDiv.Controls.Add(p1);
                HoverDiv.Controls.Add(p2);
                article.Controls.Add(HoverDiv);
                ColDiv.Controls.Add(article);
                RandomProducts.Controls.Add(ColDiv);

            }
        }//End Page Load
Esempio n. 3
0
        //returns a customer from the user name of the customer
        public Customer ReturnCustomer(string n)
        {
            using (ProductDb db = new ProductDb())
            {
                Customer customer = new Customer();
                CustomerLogin cl = db.CustomerLogins.Include(c => c.Customer).SingleOrDefault(c => c.UserName == n);
                if (cl != null)
                    customer = db.Customers.SingleOrDefault(cust => cust.CustomerId == cl.Customer.CustomerId);

                return customer;
            }
        }
Esempio n. 4
0
 //Create a delegate and event
 public void Delegate(int customerid)
 {
     CustomerLogin cust;
     using (ProductDb db = new ProductDb())
     {
         //gets the customer using the id.
         cust = db.CustomerLogins.SingleOrDefault(c => c.Customer.CustomerId == customerid);
         if (cust != null)
         {
             SignInDelegate sd = new SignInDelegate(CustomerAlert);
             sd += UpdateNavbar;
             sd += AuthCookie;
             SignInEvent = sd;
             SignInEvent(cust.UserName);
         }
     }
 }
Esempio n. 5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SignedInUser.Text = null;
                NumberInCart();
                //Check if a Customer is signed in
                if (Request.Cookies[FormsAuthentication.FormsCookieName] == null)
                {
                    SignedInUser.Visible = false;
                    hlSignIn.Visible = true;
                    hlRegister.Visible = true;
                }
                else
                {
                    // if someone is signed in it takes the information from the Auth Cookie and uses it to retrieve the customer with that user name.
                    FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
                    Customer c = ReturnCustomer(ticket.Name);
                    //Displays their first and last name in the navigation
                    SignedInUser.Text = string.Format("Hello, {0} <span class='caret'></span>", c.FirstName + " " + c.Lastname);
                    SignedInUser.Visible = true;
                    hlSignIn.Visible = false;
                    hlRegister.Visible = false;
                }
                //if remember cookie exists fill in information in sign in form
                if (Request.Cookies["Remember"] != null)
                {
                    chkRemember.Checked = true;
                    txtUsername.Text = Request.Cookies["Remember"]["Username"];
                }

            }

            using (ProductDb db = new ProductDb())
            {
                Categories = db.ProductCategorys.Include("SubCategories").ToList();

                foreach (ProductCategory pc in Categories)
                {
                    //Dynamically create a link for each Product Category in the database
                    HtmlGenericControl li = new HtmlGenericControl("li");
                    li.Attributes["class"] = "dropdown";
                    HyperLink link = new HyperLink();
                    //link.NavigateUrl = string.Format("~/Products.aspx?CategoryID={0}", pc.CatergoryID);
                    link.NavigateUrl = "#";
                    link.ID = "Category" + pc.CatergoryID.ToString();
                    link.Text = pc.CategoryType + " <span class='caret'></span>";
                    link.CssClass = "dropdown-toggle";
                    link.Attributes["role"] = "button";
                    link.Attributes["data-toggle"] = "dropdown";
                    link.Attributes["aria-expanded"] = "false";
                    HtmlGenericControl span = new HtmlGenericControl("span");
                    span.Attributes["class"] = "caret";
                    li.Controls.Add(link);
                    HtmlGenericControl ul = new HtmlGenericControl("ul");
                    ul.Attributes["class"] = "dropdown-menu";
                    ul.Attributes["role"] = "menu";
                    li.Controls.Add(ul);
                    //For each Product Category create a dropdown with links for each Sub Category in the database
                    foreach (ProductSubCategory psc in pc.SubCategories)
                    {
                        HtmlGenericControl li2 = new HtmlGenericControl("li");
                        HyperLink Sublink = new HyperLink();
                        Sublink.NavigateUrl = string.Format("~/Products.aspx?SubCategoryID={0}", psc.SubCatergoryID);
                        Sublink.Text = psc.SubCategoryType;
                        Sublink.ID = "SubCategory" + psc.SubCatergoryID.ToString();
                        li2.Controls.Add(Sublink);
                        ul.Controls.Add(li2);
                    }
                    NavList.Controls.Add(li);
                }

            }
        }