protected void Zapisz(object sender, EventArgs e) { var p = ProduktEdit1.GetProduct(); Picture picture = null; if (ProduktEdit1.UploadedFile.ContentLength > 0) { picture = new Picture(); p.AddPicture(picture); Db.Session.Save(picture); picture.SavePictures(ProduktEdit1.UploadedFile.InputStream, Server.MapPath("/Data/")); } Db.Session.Save(p); ProductList1.Visible = true; EditPanel.Visible = false; }
public void SaveWithPicture() { Product p; using (var session = factory.OpenSession()) { using (var transaction = session.BeginTransaction()) { p = new Product { Title = "Tytu³", Price = 90m, Description = "jakisopis" }; session.Save(p); var pic = new Picture(); p.AddPicture(pic); transaction.Commit(); } } using (var session = factory.OpenSession()) { var fromDb=session.Get<Product>(p.Id); Assert.That(fromDb.Pictures.Count(),Is.EqualTo(1)); } }
public virtual void AddPicture(Picture picture) { picture.Product = this; this.pictures.Add(picture); }