public ActionResult JsonData() { var db = new FabricsEntities(); db.Configuration.LazyLoadingEnabled = false; var data = db.Product.Take(5).ToList(); return Json(data); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { using (var db = new FabricsEntities()) { //if (db.Client.Find(1).City == "Taipei") //{ //} } yield break; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) { using (var db = new FabricsEntities()) { //if (db.Client.Find(1).City == "Taipei") //{ //} } yield break; }
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" })); } }
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; }
// 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; }
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"; }
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; }