예제 #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();
        }
예제 #7
0
        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;
        }