protected void btnSave_Click(object sender, EventArgs e) { try { //connect using (DefaultConnectionEF conn = new DefaultConnectionEF()) { //make a new boughtitem object in memory SoldItem s = new SoldItem(); //fill the properties of our item object from the form inputs s.ItemName = txtItemName.Text; s.Description = txtItemDescription.Text; s.SoldCost = Convert.ToDecimal(txtCost.Text); s.Profit = Convert.ToDecimal(txtPrice.Text) - Convert.ToDecimal(txtCost.Text); s.BoughtItemID = Convert.ToInt32(ItemID.Text); if (Request.QueryString.Count == 0) { conn.SoldItems.Add(s); } conn.SaveChanges(); //redirect to inventory page Response.Redirect("inventory.aspx"); } } catch { Response.Redirect("error.aspx"); } }
protected void delete() { try { Int32 BoughtItemID = Convert.ToInt32(Request.QueryString["BoughtItemID"]); //connect using (DefaultConnectionEF conn = new DefaultConnectionEF()) { var items = (from item in conn.BoughtItems where item.BoughtItemID == BoughtItemID select item); var cnt = items.Count(); BoughtItem i = (items).FirstOrDefault(); //delete record conn.BoughtItems.Remove(i); conn.SaveChanges(); } } catch { Response.Redirect("error.aspx"); } }