public void Dispose() { if(db != null) { db.Dispose(); db = null; } }
public List<Product> GetProduct() { WebFormDbContext db = new WebFormDbContext(); List<Product> model = null; int id = int.Parse(Request.QueryString["id"]); if (id > 0) { model = db.Products.Where(p => p.CategoryId == id).ToList(); } return model; }
public Product Detail() { WebFormDbContext db = new WebFormDbContext(); int id = int.Parse(Request.QueryString["ProductId"]); Product model = null; if (id > 0) { model = db.Products.Single(p => p.Id == id); } else { model = null; } return model; }
public void Add(int Id) { try { var prod = Items.Single(p => p.Id == Id); prod.Quantity++; } catch { using (var db = new WebFormDbContext()) { var prod = db.Products.Find(Id); prod.Quantity = 1; Items.Add(prod); } } }