public void Update(PickupDropoff pickupDropoff) { using (ISession session = NHibernateHelper.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { session.Update(pickupDropoff); transaction.Commit(); } }
public void Can_add_multiple_new_pickupDropoffs() { ISession session = _sessionFactory.OpenSession(); int countBefore = getPickupDropoffTableSize(session); ITransaction tx = session.BeginTransaction(); PickupDropoff pickupDropoff1 = new PickupDropoff(); pickupDropoff1.Date = DateTime.Now; pickupDropoff1.Dog = _dog1; pickupDropoff1.User = _user1; session.Save(pickupDropoff1); PickupDropoff pickupDropoff2 = new PickupDropoff(); pickupDropoff2.Date = DateTime.Now; pickupDropoff2.Dog = _dog2; pickupDropoff2.User = _user2; session.Save(pickupDropoff2); PickupDropoff pickupDropoff3 = new PickupDropoff(); pickupDropoff3.Date = DateTime.Now; pickupDropoff3.Dog = _dog1; pickupDropoff3.User = _user1; session.Save(pickupDropoff3); tx.Commit(); Assert.AreEqual(countBefore + 3, getPickupDropoffTableSize(session)); tx = session.BeginTransaction(); session.Delete(pickupDropoff1); session.Delete(pickupDropoff2); session.Delete(pickupDropoff3); tx.Commit(); session.Close(); }
public void Can_add_new_pickupDropoff() { DateTime date = DateTime.Now; // Set the Milliseconds to 0 since MySQL DATETIME does not support milliseconds. date = DateTime.ParseExact(date.ToString(), "M/d/yyyy h:mm:ss tt", null); var pickupDropoff = new PickupDropoff(date, _dog1, _user1); IPickupDropoffRepository repository = new PickupDropoffRepository(); repository.Add(pickupDropoff); // use session to try to load the pickupDropoff using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<PickupDropoff>(pickupDropoff.PickupDropoffId); // Test that the pickupDropoff was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(pickupDropoff, fromDb); Assert.AreEqual(pickupDropoff.Date, fromDb.Date); Assert.AreEqual(pickupDropoff.Dog, fromDb.Dog); Assert.AreEqual(pickupDropoff.User, fromDb.User); } repository.Remove(pickupDropoff); }
private bool IsInCollection(PickupDropoff pickupDropoff, ICollection<PickupDropoff> fromDb) { bool result = false; foreach (var item in fromDb) { if (pickupDropoff.PickupDropoffId == item.PickupDropoffId) { result = true; break; } } return result; }
private void CreateInitialData() { using (ISession session = _sessionFactory.OpenSession()) using (ITransaction transaction = session.BeginTransaction()) { // Save the user to populate its UserId. session.Save(_user1); session.Save(_user2); session.Save(_dog1); session.Save(_dog2); session.Save(_pickupCost); session.Save(_dropoffCost); session.Save(_newPickupCost); // Get rid of milliseconds to make comparisons work, since MySQL // DateTime does not support milliseconds. DateTime date = DateTime.ParseExact(DateTime.Now.ToString(), "M/d/yyyy h:mm:ss tt", null); _pickupDropoffs = new PickupDropoff [4]; _pickupDropoffs[0] = new PickupDropoff(date, _dog1, _user1); _pickupDropoffs[1] = new PickupDropoff(date, _dog1, _user2); _pickupDropoffs[2] = new PickupDropoff(date, _dog2, _user1); _pickupDropoffs[3] = new PickupDropoff(date, _dog2, _user2); foreach (var pickupDropoff in _pickupDropoffs) { pickupDropoff.PickupCost = _pickupCost; pickupDropoff.DropoffCost = _dropoffCost; session.Save(pickupDropoff); } transaction.Commit(); } }
private bool dataGridView1_RowValidating(int index, PickupDropoff pickupDropoff) { if (pickupDropoff.Date < payrollStartDate || pickupDropoff.Date > payrollEndDate) { dataGridView1.Rows[index].ErrorText = "Pickup/Dropoff Date must be for current payroll period (" + payrollStartDate + " - " + payrollEndDate + ")."; return false; } if (pickupDropoff.Dog == null) { dataGridView1.Rows[index].ErrorText = "Dog's Name must not be empty."; return false; } bool pickupOrDropoffCostFilled = false; if (pickupDropoff.PickupCost != null) { pickupOrDropoffCostFilled = true; } else if (pickupDropoff.DropoffCost != null) { pickupOrDropoffCostFilled = true; } if (!pickupOrDropoffCostFilled) { dataGridView1.Rows[index].ErrorText = "Either Pickup Cost or Dropoff Cost (or both) must filled."; return false; } return true; }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.IsCurrentCellDirty) { if (dirtyObjectsMap.Keys.Contains(e.RowIndex)) { dirtyObjectsMap.Remove(e.RowIndex); } PickupDropoff pickupDropoff = new PickupDropoff(); DateTime date = (DateTime)dataGridView1.Rows[e.RowIndex].Cells["DateColumn"].Value; pickupDropoff.Date = date; string dogId = (string)dataGridView1.Rows[e.RowIndex].Cells["DogNameColumn"].Value; DogRepository dogRepository = new DogRepository(); if (dogId != null) { Dog dog = dogRepository.GetById(dogId); pickupDropoff.Dog = dog; } CostRepository costRepository = new CostRepository(); string pickupCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["PickupCostColumn"].Value; if (pickupCostId != null) { Cost cost = costRepository.GetById(pickupCostId); pickupDropoff.PickupCost = cost; } string dropoffCostId = (string)dataGridView1.Rows[e.RowIndex].Cells["DropoffCostColumn"].Value; if (dropoffCostId != null) { Cost cost = costRepository.GetById(dropoffCostId); pickupDropoff.DropoffCost = cost; } pickupDropoff.User = user; string pickupDropoffId = (string)dataGridView1.Rows[e.RowIndex].Cells["PickupDropoffIdColumn"].Value; pickupDropoff.PickupDropoffId = pickupDropoffId; // Add object to dirty objects map. dirtyObjectsMap.Add(e.RowIndex, pickupDropoff); // Remove the entry from the delete map, if // an entry for the Daycare exists in the // delete map already. if (deleteObjectsMap.Keys.Contains(e.RowIndex)) { deleteObjectsMap.Remove(e.RowIndex); } var isSelected = dataGridView1.Rows[e.RowIndex].Cells["SelectColumn"].Value; if (isSelected != null && (bool)isSelected) { deleteObjectsMap.Add(e.RowIndex, pickupDropoff); } } }