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(); }
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(); }
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); } }