private void CheckCanDeleteProduct() { var product = new OsyProduct() { Name = "Coke", Category = "Drinks" }; IProductRepository repository = new ProductRepository(); repository.Add(product); Guid oldId = product.Id; Console.WriteLine(string.Format("Removing product with id: {0}", oldId)); repository.Remove(product); OsyProduct result = repository.GetById(oldId); Console.WriteLine(result != null ? string.Format("product with id {0} is in DB", oldId) : string.Format("product with id {0} is not in DB", oldId)); }
private void AddProduct() { var product = new OsyProduct { Name = "Apple", Category = "Fruit" }; IProductRepository repository = new ProductRepository(); repository.Add(product); OsyProduct fromDb = repository.GetById(product.Id); if (product.Id == fromDb.Id && product.Name == fromDb.Name && product.Category == fromDb.Category && product.Discontinued == fromDb.Discontinued) { Console.WriteLine("Equal"); } else { Console.WriteLine("Not equal"); } Console.WriteLine(Object.ReferenceEquals(product, fromDb) ? "references equal" : "references not equal"); }
private void RunTransaction(Action<ISession, OsyProduct> command, OsyProduct product) { using (ISession session = SessionHelper.OpenSession()) { using (ITransaction transaction = session.BeginTransaction()) { command(session, product); transaction.Commit(); // NOTE: also could call session.Transation.Commit(); } } }
private void RemoveHelper(ISession session, OsyProduct product) { session.Delete(product); }
private void AddHelper(ISession session, OsyProduct product) { session.Save(product); }
public void Update(OsyProduct product) { RunTransaction(UpdateHelper, product); }
public void Remove(OsyProduct product) { RunTransaction(RemoveHelper, product); }
public void Add(OsyProduct product) { RunTransaction(AddHelper, product); }
private void UpdateHelper(ISession session, OsyProduct product) { session.Update(product); }
private void InsertOsyProduct() { var osyProduct = new OsyProduct { Name = "Coke", Category = "Drinks" }; Insert(osyProduct); Console.WriteLine("done inserting product"); }