示例#1
0
        protected void loadgrid2()
        {
            tokobediaModelContainer db   = new tokobediaModelContainer();
            List <Product>          prod = new List <Product>();
            Random rnd    = new Random();
            int    value1 = 0;
            int    value2 = 0;
            int    value3 = 0;
            int    value4 = 0;
            int    value5 = 0;
            var    v      = db.Products.OrderByDescending(t => t.ID).First();
            var    d      = db.Products.OrderBy(c => c.ID).First();
            var    e      = db.Products.ToList().Count;

            do
            {
                value1 = rnd.Next(1, e);
            } while (ProductRepository.checkProductId(value1) == null);
            do
            {
                value2 = rnd.Next(1, e);
            } while (ProductRepository.checkProductId(value2) == null || value2 == value1);
            do
            {
                value3 = rnd.Next(1, e);
            } while (ProductRepository.checkProductId(value3) == null || value3 == value2 || value3 == value1);
            do
            {
                value4 = rnd.Next(1, e);
            } while (ProductRepository.checkProductId(value4) == null || value4 == value3 || value4 == value2 || value4 == value1);
            do
            {
                value5 = rnd.Next(1, e);
            } while (ProductRepository.checkProductId(value5) == null || value5 == value4 || value5 == value3 || value5 == value2 || value5 == value1);
            var query = from g in db.Products
                        join m in db.ProductTypes on g.ID equals m.ID
                        where g.ID == value1 || g.ID == value2 || g.ID == value3 || g.ID == value4 || g.ID == value5
                        select new
            {
                productId       = g.ID,
                productTypeName = m.Name,
                ProductName     = g.Name,
                ProductPrice    = g.Price,
                ProductStock    = g.Stock
            };

            GridRandomItem.DataSource = query.ToList();
            GridRandomItem.DataBind();
        }
示例#2
0
        private void SetRandomItem()
        {
            List <Product> product = HomeController.GetFiveRandomProductController();

            var filtered = product.Select(i => new {
                productId    = i.ID,
                ProductName  = i.Name,
                ProductPrice = i.Price,
                ProductStock = i.Stock
            });

            if (product.Count > 0)
            {
                GridRandomItem.DataSource = filtered;
                GridRandomItem.DataBind();
            }
        }