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 string AddCategoriesToGoods(int selectedCategoryID, int selectedGoodsID) { if (!isContains(selectedCategoryID, selectedGoodsID)) { var entity = new RelationsCategoriesGoods(); entity.Categories = Sessions.NewSession.Get <Categories>(selectedCategoryID); entity.Goods = Sessions.NewSession.Get <Goods>(selectedGoodsID); Sessions.NewSession.SaveOrUpdate(entity); Sessions.NewSession.Flush(); return("Added successfully"); } else { return("Goods have a contains this category, please select another category"); } }