protected void Button1_Click(object sender, EventArgs e) { String name = TextBox1.Text.Trim(); decimal price = Convert.ToDecimal(TextBox2.Text.Trim()); decimal marketprice = Convert.ToDecimal(TextBox3.Text.Trim()); int qty = Convert.ToInt32(TextBox4.Text.Trim()); int brandId = Convert.ToInt32(DropDownList1.SelectedValue); int genderId = Convert.ToInt32(DropDownList2.SelectedValue); int id; using (LiBoClothesShopEntities context = new LiBoClothesShopEntities()) { Cloth cloth = new Cloth(); cloth.Name = name; cloth.Price = price; cloth.OriginalPrice = marketprice; cloth.Qty = qty; cloth.BrandId = brandId; cloth.GenderId = genderId; context.AddToClothes(cloth); context.SaveChanges(); id = cloth.Id; foreach (ListItem item in CheckBoxList1.Items) { if (item.Selected) { ClothSzie size = new ClothSzie(); size.Cloth = cloth; size.SizeId = Convert.ToInt32(item.Value); context.AddToClothSzies(size); } } context.SaveChanges(); foreach (ListItem item in CheckBoxList2.Items) { if (item.Selected) { ColthColor color = new ColthColor(); color.Cloth = cloth; color.ColorId = Convert.ToInt32(item.Value); context.AddToColthColors(color); } } context.SaveChanges(); } Response.Redirect(String.Format("~/AddClothStep2.aspx?id={0}", id)); }
/// <summary> /// Deprecated Method for adding a new object to the ClothSzies EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToClothSzies(ClothSzie clothSzie) { base.AddObject("ClothSzies", clothSzie); }
/// <summary> /// Create a new ClothSzie object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="sizeId">Initial value of the SizeId property.</param> /// <param name="clothId">Initial value of the ClothId property.</param> public static ClothSzie CreateClothSzie(global::System.Int32 id, global::System.Int32 sizeId, global::System.Int32 clothId) { ClothSzie clothSzie = new ClothSzie(); clothSzie.Id = id; clothSzie.SizeId = sizeId; clothSzie.ClothId = clothId; return clothSzie; }