public void PayrollTracker_SaveButtonClickedEventHandler(object sender, EventArgs e) { GroomingRepository repository = new GroomingRepository(); foreach (KeyValuePair<int, Grooming> entry in dirtyObjectsMap) { Grooming grooming = entry.Value; bool isValid = groomingDataGridView_RowValidating(entry.Key, grooming); if (isValid) { if (grooming.GroomingId == null) { repository.Add(grooming); } else { repository.Update(grooming); } dirtyObjectsMap = new Dictionary<int, Grooming>(); refreshDisplayFromDatabase(); } } }
public void PayrollTracker_DeleteButtonClickedEventHandler(object sender, EventArgs e) { GroomingRepository repository = new GroomingRepository(); foreach (KeyValuePair<int, Grooming> entry in deleteObjectsMap) { Grooming grooming = entry.Value; if (grooming.GroomingId != null) { repository.Remove(grooming); } } deleteObjectsMap = new Dictionary<int, Grooming>(); refreshDisplayFromDatabase(); }
public void Can_add_new_grooming() { 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 grooming = new Grooming(_groomingType1, 245.50, date, _dog1, _user1); IGroomingRepository repository = new GroomingRepository(); repository.Add(grooming); // use session to try to load the grooming using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Grooming>(grooming.GroomingId); // Test that the grooming was successfully inserted Assert.IsNotNull(fromDb); Assert.AreNotSame(grooming, fromDb); Assert.AreEqual(grooming.GroomingType, fromDb.GroomingType); Assert.AreEqual(grooming.Cost, fromDb.Cost); Assert.AreEqual(grooming.Date, fromDb.Date); Assert.AreEqual(grooming.Dog, fromDb.Dog); Assert.AreEqual(grooming.User, fromDb.User); } repository.Remove(grooming); }
private void DeleteInitialData() { IGroomingRepository groomingRepository = new GroomingRepository(); foreach (var grooming in _groomings) { Grooming fromDb = groomingRepository.GetById(grooming.GroomingId); if (fromDb != null) { groomingRepository.Remove(grooming); } } IUserRepository userRepository = new UserRepository(); userRepository.Remove(_user1); userRepository.Remove(_user2); IDogRepository dogRepository = new DogRepository(); dogRepository.Remove(_dog1); dogRepository.Remove(_dog2); IGroomingTypeRepository groomingTypeRepository = new GroomingTypeRepository(); groomingTypeRepository.Remove(_groomingType1); groomingTypeRepository.Remove(_groomingType2); }
public void Can_update_existing_grooming() { var grooming = _groomings[1]; grooming.Tip = 30.00; IGroomingRepository repository = new GroomingRepository(); repository.Update(grooming); // use session to try to load the grooming using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Grooming>(grooming.GroomingId); Assert.AreEqual(grooming.Tip, fromDb.Tip); } }
public void Can_remove_existing_grooming() { var grooming = _groomings[0]; IGroomingRepository repository = new GroomingRepository(); repository.Remove(grooming); using (ISession session = _sessionFactory.OpenSession()) { var fromDb = session.Get<Grooming>(grooming.GroomingId); Assert.IsNull(fromDb); } }
public void Can_get_existing_grooming_by_id() { IGroomingRepository repository = new GroomingRepository(); var fromDb = repository.GetById(_groomings[1].GroomingId); Assert.IsNotNull(fromDb); Assert.AreNotSame(_groomings[1], fromDb); Assert.AreEqual(_groomings[1].GroomingType, fromDb.GroomingType); Assert.AreEqual(_groomings[1].Cost, fromDb.Cost); Assert.AreEqual(_groomings[1].Date, fromDb.Date); Assert.AreEqual(_groomings[1].Dog, fromDb.Dog); Assert.AreEqual(_groomings[1].User, fromDb.User); }
public void Can_get_existing_groomings_by_user_id() { IGroomingRepository repository = new GroomingRepository(); var fromDb = repository.GetByUser(_groomings[1].User); Assert.AreEqual(2, fromDb.Count); Assert.IsTrue(IsInCollection(_groomings[1], fromDb)); }
private void refreshDisplayFromDatabase() { this.groomingDataGridView.Rows.Clear(); GroomingRepository groomingRepository = new GroomingRepository(); IList<Grooming> groomingsList = groomingRepository.GetRecentGroomings(user, payrollStartDate, payrollEndDate); foreach (Grooming grooming in groomingsList) { int index = this.groomingDataGridView.Rows.Add(); groomingDataGridView.Rows[index].Cells["DateColumn"].Value = grooming.Date; groomingDataGridView.Rows[index].Cells["DogNameColumn"].Value = grooming.Dog.DogId; groomingDataGridView.Rows[index].Cells["GroomTypeColumn"].Value = grooming.GroomingType.GroomingTypeId; groomingDataGridView.Rows[index].Cells["CostColumn"].Value = grooming.Cost.ToString(); groomingDataGridView.Rows[index].Cells["TipColumn"].Value = grooming.Tip.ToString(); groomingDataGridView.Rows[index].Cells["GroomingIdColumn"].Value = grooming.GroomingId; } }