public void Remove(Manafacturer manafacturer) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Delete(manafacturer); transaction.Commit(); } }
public ActionResult AddNewManafacturer(ManafacturerViewModel model) { var newManafacturer = new Manafacturer { Name = model.ManafacturerName, Website = model.ManafacturerWebsite }; _manafacturerRepository.Add(newManafacturer); return Redirect("/Admin/Index"); }
public void CanAddNewManafacturer() { var manafacturer = new Manafacturer { Name = "TestManafacturer 6", Website = "www.testco6.co.uk" }; IManafacturerRepository repository = new ManafacturerRepository(); repository.Add(manafacturer); // use session to try to load the Manafacturer using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Manafacturer>(manafacturer.ManafacturerId); // Test that the Manafacturer was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(manafacturer, fromDb); Assert.AreEqual(manafacturer.Name, fromDb.Name); Assert.AreEqual(manafacturer.Website, fromDb.Website); } }
private static bool IsInManafacturerCollection(Manafacturer manafacturer, IEnumerable<Manafacturer> fromDb) { return fromDb.Any(item => manafacturer.ManafacturerId == item.ManafacturerId); }
public void CanCheckAndAddManafacturerWhereNotExisting() { var manafacturer = new Manafacturer { Name = "TestManafacturer 7", Website = "www.testco7.co.uk" }; IManafacturerRepository repository = new ManafacturerRepository(); var fromDb = repository.DistinctNamesList(); Assert.IsFalse(IsInManafacturerNameCollection(manafacturer.Name, fromDb)); var newManFromDb = repository.GetByManafacturerId(repository.CheckExistingNamesAdd(manafacturer.Name)); Assert.IsTrue(manafacturer.Name == newManFromDb.Name); }