public ActionResult Create(Product book) { //try //{ _productRepository.SaveOrUpdate(book); return RedirectToAction("Index"); //} //catch (Exception exception) //{ // TempData["warning"] = exception.Message; // return View(); //} }
public void CreateNew() { var product = new Product { Name = "Laptop", Metadata = new Dictionary<string, ProductMetadata> { {"he", new ProductMetadata { Name = "Fuji", Description = "Hi performance laptop", }} } }; Session.Save(product); Session.Flush(); }
public void RecreateDataBase() { using (var session = SessionManager.SessionFactory.OpenSession()) { using (TextWriter stringWriter = new StreamWriter("../../../Gen/DataBase.sql")) { new SchemaExport(SessionManager.Configuration).Execute(true, true, false, session.Connection, stringWriter); } } using (var session = SessionManager.SessionFactory.OpenSession()) using (var trans = session.BeginTransaction()) { // create initial data var product = new Product { Name = "Laptop", Price = 5000, Metadata = new Dictionary<string, ProductMetadata> { {"en", new ProductMetadata { Name = "Fuji", Description = "Hi performance laptop", }} } }; session.Save(product); session.Flush(); var customer = new Customer { FirstName = "Joe", LastName = "Smith", Type = CustomerType.Private, Orders = new List<Order>(), }; session.Save(customer); session.Flush(); var order = new Order { Customer = customer, Products = new List<ProductInOrder> { new ProductInOrder { Product = product, Quantity = 2, } } }; session.Save(order); session.Flush(); trans.Commit(); } }