Example #1
0
 public void GetBestSellerProducts()
 {
     var _db = new ProductContext();
     ProductActions productAction = new ProductActions();
     List<Product> query = new List<Product>();
     query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 4).ToList();
     query = query.OrderByDescending(i => productAction.GetUnitSold(i.ProductID)).Take(4).ToList();
     productListBstSlr.DataSource = query;
     productListBstSlr.DataBind();
 }
Example #2
0
 public void GetProducts(string id)
 {
     var _db = new ProductContext();
     ProductActions productAction = new ProductActions();
     List<Product> query = new List<Product>();
     int catID = 0;
     bool r = Int32.TryParse(id, out catID);
     if (r && catID > 0)
     {
         query = _db.Products.Where(p => p.CategoryID == catID && p.Status == true && p.UnitInStock > 0).ToList();
         Title = _db.Categories.Where(c => c.CategoryID == catID).FirstOrDefault().CategoryName;
     }
     else if (id=="new")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 1).ToList();
         query = query.OrderBy(i => i.CreatedDate).ToList();
         Title = "Special Offer";
     }
     else if (id == "bestseller")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.LabelID == 4).ToList();
         query = query.OrderByDescending(i => productAction.GetUnitSold(i.ProductID)).ToList();
         Title = "Best Sellers";
     }
     else if (id == "special")
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0 && p.Discount != 0).ToList();
         query = query.OrderByDescending(i => i.Discount).ToList();
         Title = "Special Offer";
     }
     else
     {
         query = _db.Products.Where(p => p.Status == true && p.UnitInStock > 0).ToList();
         Title = "Browse Products";
     }
     productList.DataSource = query;
     productList.DataBind();
 }
Example #3
0
        private static void CheckLabel()
        {
            ProductContext _db = new ProductContext();
            ProductActions productAction = new ProductActions();
            while (true)
            {
                foreach (var item in _db.Products.ToList())
                {
                    DateTime date = (DateTime)item.CreatedDate;
                    DateTime newDate = DateTime.Now;
                    // Difference in days, hours, and minutes.
                    TimeSpan ts = newDate - date;
                    // Difference in days.
                    int differenceInDays = ts.Days;
                    if (differenceInDays >= 365)
                    {
                        if (item.Discount<0.50)
                        {
                            item.Discount = 0.50;
                        }
                        item.LabelID = 3;
                    }
                    else if (productAction.GetUnitSold(item.ProductID) >= 1000)
                    {
                        item.LabelID = 4;
                    }

                    else if (differenceInDays >= 7)
                    {
                        item.LabelID = 2;
                    }

                }
                _db.SaveChanges();
                Thread.Sleep(5000);
            }
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            productAction = new ProductActions();
            categoryAction = new CategoryActions();
            SetValidation();

            if (!Page.IsPostBack)
            {
                if (GetCatCount()>=8)
                {
                    btnAddCat.Enabled = false;
                }

                string Action = Request.QueryString["Action"];
                switch (Action)
                {
                    case ("addProduct"):
                        lblNotis.InnerText = "Product was added successfully.";
                        ModalNotisfication.Show();
                        break;
                    case ("editProduct"):
                        lblNotis.InnerText = "Product was edited successfully.";
                        ModalNotisfication.Show();
                        break;
                    case ("removeProduct"):
                        lblNotis.InnerText = "Product was deleted successfully.";
                        ModalNotisfication.Show();
                        break;
                    case ("addCategory"):
                        lblNotis.InnerText = "Category was added successfully";
                        ModalNotisfication.Show();
                        break;
                    case ("removeCategory"):
                        lblNotis.InnerText = "Category was edited successfully";
                        ModalNotisfication.Show();
                        break;
                    case ("deleteCategory"):
                        lblNotis.InnerText = "Category was deleted successfully";
                        ModalNotisfication.Show();
                        break;
                    default:
                        break;
                }

            }

            if ((GetCategories().ToList()).Count >= 8)
            {

            }
        }