Exemple #1
0
        public ActionResult PriceDown_Each(int?id)
        {
            var db = new FabricsEntities();

            db.Database.ExecuteSqlCommand("UPDATE dbo.Product SET Price=Price-1 WHERE ProductId=" + id);

            return(RedirectToAction("Top10"));
        }
Exemple #2
0
        public ActionResult PriceUp()
        {
            var db = new FabricsEntities();

            foreach (var item in db.Product)
            {
                item.Price += 1;
            }
            db.SaveChanges();
            //db.Database.ExecuteSqlCommand("UPDATE dbo.Product SET Price=Price+1");

            return(RedirectToAction("Top10"));
        }
Exemple #3
0
        public ActionResult PriceUp_Each(int?id)
        {
            var db = new FabricsEntities();

            foreach (var item in db.Product)
            {
                if (null != id && id == item.ProductId)
                {
                    item.Price += 1;
                }
            }
            db.SaveChanges();

            return(RedirectToAction("Top10"));
        }
Exemple #4
0
        public ActionResult TOP10()
        {
            var db = new FabricsEntities();

            var result = db.Product.Take(10);

            // LINQ ( C# 3.0 )
            //var data = from p in result
            //           select new ProductCreationVM()
            //           {
            //               ProductId = p.ProductId,
            //               ProductName = p.ProductName,
            //               Price = p.Price,
            //               OrderLineCount = p.OrderLine.Count()
            //           };
            //var data = "SELECT * FROM table WHERE ...";
            var data = db.Database.SqlQuery <ProductCreationVM>(
                "SELECT TOP 10*, OrderLineCount=(SELECT COUNT(*) FROM dbo.OrderLine o WHERE o.ProductId=p.ProductId) FROM dbo.Product p");

            return(View(data));
        }