public void SaveEditGoods(Goods goods, GoodsImages goodsImages, int goodsID) { using (Sessions.NewSession = Sessions.SessionFactory.OpenSession()) { using (var transaction = Sessions.NewSession.BeginTransaction()) { var entity = Sessions.NewSession.Get <Goods>(goodsID); entity.Name = goods.Name; entity.Price = goods.Price; entity.Discount = goods.Discount; entity.IsDiscount = goods.IsDiscount; Sessions.NewSession.SaveOrUpdate(entity); Sessions.NewSession.Flush(); var images = (from q in Sessions.NewSession.Linq <GoodsImages>() where q.Goods.ID == goodsID select q).FirstOrDefault <GoodsImages>(); if (goodsImages.Image != null) { images.Image = goodsImages.Image; } if (goodsImages.MiniImage != null) { images.MiniImage = goodsImages.MiniImage; } Sessions.NewSession.SaveOrUpdate(images); Sessions.NewSession.Flush(); transaction.Commit(); } } }
public int AddGoods(Goods goods, GoodsImages goodsImages, int categoryID) { using (Sessions.NewSession = Sessions.SessionFactory.OpenSession()) { using (var transaction = Sessions.NewSession.BeginTransaction()) { //write goods in db Sessions.NewSession.SaveOrUpdate(goods); Sessions.NewSession.Flush(); //write relations in db var entity = new RelationsCategoriesGoods(); entity.Categories = Sessions.NewSession.Get <Categories>(categoryID); entity.Goods = Sessions.NewSession.Get <Goods>(goods.ID); Sessions.NewSession.SaveOrUpdate(entity); Sessions.NewSession.Flush(); //write images in db goodsImages.Goods = Sessions.NewSession.Get <Goods>(goods.ID); Sessions.NewSession.SaveOrUpdate(goodsImages); Sessions.NewSession.Flush(); transaction.Commit(); } } return(goodsImages.ID); }
public void ButtonAdd_Click(object sender, EventArgs e) { string name = TextBoxName.Text; float price; float.TryParse(TextBoxPrice.Text, out price); bool isDiscount = CheckBox1.Checked; int discount; int.TryParse(TextBoxDiscount.Text, out discount); byte[] image = null; byte[] miniImage = null; if (FileUploadImage.HasFile) { image = FileUploadImage.FileBytes; } if (FileUploadMiniImage.HasFile) { miniImage = FileUploadMiniImage.FileBytes; } var args = new ButtonSubmitEventArgs(name, price, isDiscount, discount, image, miniImage); ButtonAdd_OnClick(args); var goods = new Goods(); goods.Name = name; goods.Price = price; goods.IsDiscount = isDiscount; if (discount > 0) { goods.Discount = discount; } goods.AdditionDate = DateTime.Now; var goodsImages = new GoodsImages(); goodsImages.Image = image; goodsImages.MiniImage = miniImage; GoodsActions goodsActions = new GoodsActions(); goodsActions.AddGoods(goods, goodsImages, goodsID); Response.Redirect("~/Administrator/GoodsPreview.aspx"); }
public void SaveEditGoods(Goods goods, GoodsImages goodsImages, int goodsID) { GoodsCRUD goodsCRUD = new GoodsCRUD(); goodsCRUD.SaveEditGoods(goods, goodsImages, goodsID); }
public int AddGoods(Goods goods, GoodsImages goodsImages, int categotyID) { GoodsCRUD goodsCRUD = new GoodsCRUD(); return(goodsCRUD.AddGoods(goods, goodsImages, categotyID)); }