protected void btnDelete_Click(object sender, EventArgs e) { using (var context = new StoreEntities()) { var productToDelete = context.Products.Find(Int32.Parse(ddlProducts.SelectedValue)); if (productToDelete != null) { context.Products.Remove(productToDelete); context.SaveChanges(); BindGridAllProducts(); } } }
protected void btnUpdate_Click(object sender, EventArgs e) { using (var entities = new StoreEntities()) { var product = entities.Products.Find(Int32.Parse(txtUpdateProductId.Text)); product.Name = txtUpdateProductName.Text; product.Description = txtUpdateProductDescription.Text; product.Price = decimal.Parse(txtUpdateProductPrice.Text); entities.Entry(product).State = System.Data.EntityState.Modified; entities.SaveChanges(); BindGridAllProducts(); } pnlEditProduct.Visible = false; }
protected void btnInsertNewProduct_Click(object sender, EventArgs e) { using (var context = new StoreEntities()) { context.Products.Add(new Product { ProductId = Int32.Parse(txtNewProductId.Text), Name = txtNewProductName.Text, Description = txtNewProductDescription.Text, Price = decimal.Parse(txtNewProductPrice.Text) }); context.SaveChanges(); BindGridAllProducts(); txtNewProductName.Text = ""; txtNewProductDescription.Text = ""; txtNewProductPrice.Text = ""; } }