示例#1
0
 public ActionResult JsonData()
 {
     var db = new FabricsEntities();
     db.Configuration.LazyLoadingEnabled = false;
     var data = db.Product.Take(5).ToList();
     return Json(data);
 }
示例#2
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            using (var db = new FabricsEntities())
            {
                //if (db.Client.Find(1).City == "Taipei")
                //{

                //}
            }

            yield break;
        }
示例#3
0
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            using (var db = new FabricsEntities())
            {
                //if (db.Client.Find(1).City == "Taipei")
                //{

                //}
            }

            yield break;
        }
示例#4
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            var orderLines = new FabricsEntities().OrderLine.Where(o => o.ProductId == this.ProductId).ToList();

            if (this.Stock.GetValueOrDefault(0) < orderLines.Count)
            {
                yield return(new ValidationResult("庫存過小!", new[] { "Stock" }));
            }
            if (Price >= 1000M)
            {
                yield return(new ValidationResult("Prcie 不可大於 1000.00!", new[] { "Price" }));
            }
        }
示例#5
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            if (this.Price > 100 && this.Stock > 5)
            {
                yield return(new ValidationResult("價格與庫存數量不合理",
                                                  new string[] { "Price", "Stock" }));
            }

            using (var db = new FabricsEntities())
            {
                var prod = db.Product.FirstOrDefault(p => p.ProductId == this.ProductId);
                if (prod != null && prod.OrderLine.Count() > 5 && this.Stock == 0)
                {
                    yield return(new ValidationResult("Stock 與訂單數量不匹配",
                                                      new string[] { "Stock" }));
                }
            }

            yield break;
        }
示例#6
0
        // GET: MB
        public ActionResult Index()
        {
            var data = new NewProductVM()
            {
                Price = 100,
                ProductName = "T-Shirt"
            };

            ViewData["MyTitle"] = "will";
            ViewBag.MyTitle = "will 2";

            var db = new FabricsEntities();
            db.Configuration.LazyLoadingEnabled = false;
            ViewBag.Products = db.Product.Take(5).ToList();

            TempData["Msg"] = "TEST!";

            ViewData.Model = data;
            return View();
        }
        public string TestInsert()
        {
            var db = new FabricsEntities();

            var product = new Product()
            {
                ProductName = "Entity",
                Price = 99,
                Stock = 10,
                Active = true
            };

            db.Product.Add(product);

            repo.UnitOfWork.Commit();

            return "OK: " + product.ProductId;
        }
示例#8
0
        public string TestInsert()
        {
            var db = new FabricsEntities();

            db.Product.Add(new Product()
            {
                ProductName = "Entity Framework",
                Price = 99,
                Stock = 10,
                Active = true
            });

            db.SaveChanges();

            return "OK";
        }
示例#9
0
        public string TestInsert()
        {
            var db = new FabricsEntities();
            var prod = new Product()
            {
                ProductName = "EF",
                Price = 99,
                Stock = 5,
                Active = true
            };
            db.Product.Add(prod);

            db.SaveChanges();

            return "OK: "+prod.ProductId;
        }